aruns Posted March 22, 2008 Share Posted March 22, 2008 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... Quote Link to comment https://forums.phpfreaks.com/topic/97334-problem-with-db-connection/ Share on other sites More sharing options...
cunoodle2 Posted March 22, 2008 Share Posted March 22, 2008 What error messages (if any) are you getting? What are you expecting the results to be? What are the results you are actually getting? Quote Link to comment https://forums.phpfreaks.com/topic/97334-problem-with-db-connection/#findComment-498064 Share on other sites More sharing options...
aruns Posted March 22, 2008 Author Share Posted March 22, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/97334-problem-with-db-connection/#findComment-498067 Share on other sites More sharing options...
Lamez Posted March 22, 2008 Share Posted March 22, 2008 <?php $connection = mysql_connect("mysql_server_name", "db_username", "db_pass"); mysql_select_db("db_name", $connection); ?> this help? Quote Link to comment https://forums.phpfreaks.com/topic/97334-problem-with-db-connection/#findComment-498070 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.