execution sql command
what the factor that the code not work?
<?php
class mysql
{
var $user;
var $password;
var $database;
var $host;
var $out;
var $query;
function mysql($username, $password, $database, $host, $query)
{
$this开发者_高级运维->user = $username;
$this->password = $password;
$this->database = $database;
$this->host = $host;
$this->query = $query;
}
function connect()
{
$this->out = mysql_connect($this->host, $this->user, $this->password)
or die("Error cannnot connect to mysql server");
echo "Connected successfully to Mysql server";
mysql_select_db($this->database) or die("Cannot select db");
}
function execution()
{
$re = mysql_query($this->query);
while($row = mysql_fetch_array($re))
echo $row;
}
function out()
{
mysql_close($this->out);
}
}
$connect = new mysql('root','','test','127.0.0.1');
$connect->connect();
$connect->execution('test','SELECT * FROM test');
$connect->out;
?>
Update
$connect = new mysql('root','','test','127.0.0.1','SELECT ss from test');
I have trying above code and its dont return nothing..
ss contain an column name ID and its contain the 11 value.
It looks like a couple of your function calls are passing the incorrect amount of parameters. Your mysql() constructor should take 5 but you're only giving it 4. Also, execution() doesn't take any and you're trying to give it 2.
Your constructor should be new mysql('root','','test','127.0.0.1', 'SELECT * FROM test');
You are missing the $query
parameter in your mysql()
call:
$connect = new mysql('root','','test','127.0.0.1');
should be
$connect = new mysql('root','','test','127.0.0.1', 'SELECT * FROM test');
Although moving the parameter for the $query
to the execution()
method is cleaner.
精彩评论