I have set the password for root and grant all privileges for root. Why does it say it is denied?
****mysql_query() [function.mysql-query]: Access denied for user 'SYSTEM'@'localhost' (using password: NO) in C:\wamp\www\photo_gallery\includes\database.php on line 56
Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in C:\wamp\www\photo_gallery\includes\database.php on line 56
The Query has problemAccess denied for user 'SYSTEM'@'localhost' (using password: NO)
Code as follows:
<?php
include("DB_Info.php");
class MySQLDatabase
{
public $connection;
function _construct()
{
$this->open_connection();
}
public function open_connection()
{
$this->connection = mysql_connect($DB_SERVER,$DB_USER,$DB_PASS);
if(!$this->connection)
{
die("Database Connection Failed" . mysql_error());
}
else
{
$db_select = mysql_select_db($DB_NAME,$this->connection);
if(!$db_select)
{
die("Database Selection Failed" . mysql_error());
}
}
}
function mysql_prep($value)
{
if (get_magic_quotes_gpc())
{
$value = stripslashes($value);
}
// Quote if not a number
if (!is_numeric($value))
{
$value = "'" . mysql_real_escape_string($value) . "'";
}
return $value;
}
public function close_connection()
{
if(isset($this->connection))
{
mysql_close($this->connection);
unset($this->connection);
}
}
public function query($sql)
{
$result = mysql_query($sql);
$this->confirm_query($result);
return $found_user;
}
private function confirm_query($result)
{
if(!$result)
{
die("The Query has problem" . mysql_error());
}
}
}
$database = new MySQLDatabase();
?>
The missing second underscore for __construct() in
explains all the symptoms (mysql_query raising the warning, no undefined variable notices, no matter what you do to make the parameters available to
function open_connection()it doesn’t work simply because it’s never called, access denied for system@localhost because your webserver runs as localsystem and thereforesystemis the default username for the default mysql connection, …)When you create a new object via
$database = new MySQLDatabase();the method _construct() isn’t invoked and therefore neither is $this->open_connection() and therefore no value is assigned to the property $connection which remains NULL and no connection to the mysql server is established.Now when you call
$database->query('something');and there is no database connection mysql_query() tries to establish the default connection as explained at http://docs.php.net/mysql_query:open_connection()has all the parameters it needs, e.g.isset($DB_SERVER,$DB_USER,$DB_PASS,$DB_NAME) or die('missing parameters');echo "Debug: this->connection = mysql_connect($DB_SERVER,$DB_USER,$DB_PASS);\n";