0
嘗試使用以下代碼連接到localhost sql db(此時不做任何與查詢有關的查詢只是希望查詢執行):拒絕用戶'@'localhost'的訪問(使用密碼:NO)
<?php
$host = "localhost";
$port = 3306;
$socket = "";
$user = "root";
$password = "Password1";
$dbname = "CIIP_WIKI";
$con = new mysqli($host, $user, $password, $dbname, $port);
if(!$con)
{
echo ("db connection failed!");
die ('Could not connect to the database server' . mysqli_connect_error());
}
else {
echo ("db connection established.");
echo ("<br/>");
}
$query = sprintf("SELECT first_name FROM actor WHERE actor_id='1'");
$result = mysql_query($query);
$con->close();
?>
我不斷收到以下...
Welcome
db connection established.
Warning: mysql_query(): Access denied for user ''@'localhost' (using password: NO) in C:\Program Files (x86)\EasyPHP-12.1\www\Cisco Wiki\index.php on line 31
Warning: mysql_query(): A link to the server could not be established in C:\Program Files (x86)\EasyPHP-12.1\www\Cisco Wiki\index.php on line 31
爲什麼這個不行?
你混合了mysql和mysqli的。留一個API。 – 2013-02-22 00:53:25
Mysql_ *和mysqli是兩個不同的API – 2013-02-22 01:00:20
可能的重複[PHP MySQLi不識別登錄信息](http://stackoverflow.com/questions/11589210/php-mysqli-doesnt-recognize-login-info) – hakre 2013-07-01 07:25:14