1

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.

1
  • Please just edit your question to provide additional information. Additionally, you can use the comment feature under any answer on any question that you've asked. Please take some time to read the faq. Commented Apr 7, 2011 at 18:44

3 Answers 3

3

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.

Sign up to request clarification or add additional context in comments.

Comments

1

Your constructor should be new mysql('root','','test','127.0.0.1', 'SELECT * FROM test');

Comments

1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.