Jump to content

problem with db connection


aruns

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.