Jump to content

Recommended Posts

hi, guys

                  I am doing a shopping cart. but i had problem with my db connection.the script

<?
class connection {

        private $host = "localhost";

        private $database = "shopping";

        private $username = "root";

        private $password = "fairy";

        // Variables

	private $link;

        private $result;

        public $sql;


        function __construct($database=""){

                if (!empty($database)){ $this->database = $database; }

                $this->link = mysql_connect($this->module,$this->host,$this->username,$this->password);

			mysql_select_db($this->database, $this->link);

                return $this->link;  // returns false if connection could not be made.
        }

        function query($sql){

                if (!empty($sql)){

                        $this->sql = $sql;

                        $this->result = mysql_query($sql, $this->link);

                        return $this->result;

                }else{
                        return false;
                }
        }

        function fetch($result=""){

                if (empty($result)){ $result = $this->result; }

                return mysql_fetch_row($result);
        }

        function __destruct(){

                mysql_close($this->link);
        }
}



$db = new connection();

$result = $db->query("SELECT * FROM products");

while ( $row = $db->fetch($result) ){

        echo $row["name"]."\n";
}
?>

 

                      please find and let me out whats wrong with my script...

           

Link to comment
https://forums.phpfreaks.com/topic/97334-problem-with-db-connection/
Share on other sites

this..

 

 

Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'localhost'@'localhost' (using password: YES) in C:\xampp\htdocs\class.php on line 25

 

Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link resource in C:\xampp\htdocs\class.php on line 27

 

Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in C:\xampp\htdocs\class.php on line 38

 

Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\class.php on line 51

 

Warning: mysql_close(): supplied argument is not a valid MySQL-Link resource in C:\xampp\htdocs\class.php on line 56

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.