我使用phpmyadmin進行了檢查,並且我試圖執行的查詢正在工作。無法從PHP連接到服務器MySQL服務器,但它在phpmyadmin中有效
$user
=到用戶名登錄。我看到它是因爲我回應它。所以我不認爲這是錯誤。
我得到的錯誤是
> PHP Warning: mysql_query(): Can't connect to local MySQL server through socket
'/var/run/mysqld/mysqld.sock' (2) in
/hermes/bosweb/web161/b1615/ipg.jmdev/nmc/admin/user.php on line 14
> PHP Warning: mysql_query(): A link to the server could not be established in
/hermes/bosweb/web161/b1615/ipg.jmdev/nmc/admin/user.php on line 14
14號線是我的查詢線(如下圖),這是一段代碼,不工作...
這裏是我的代碼:
$host="link"; // Host name
$username="username"; // Mysql username
$password="password"; // Mysql password
$db_name="nmc"; // Database name
$tbl_name="account"; // Table name
session_start();
$user = $_SESSION['myusername'];
echo $user . '<br>';
//[Working on PHPMyAdmin](SELECT `role` FROM `account` WHERE `username`='jean8mathieu') (Working)
$result = mysql_query("SELECT `role` FROM `account` WHERE `username`='$user'");//I would like to make this work...
//$result = mysql_query("SELECT role FROM account WHERE username='jean8mathieu'"); /I try this line and did not ever work...
if (!$result) {
echo 'Could not run query: ' . mysql_error();
exit;
}
$row = mysql_fetch_row($result);
echo $row[0];
我的問題是不要在服務器上連接它的查詢。我能夠連接到它只是我的查詢似乎並不工作...它爲我所有的其他頁面工作...
「服務器的鏈接不能成立「你的密碼是否正確? –
數據庫連接在哪裏?看來你只是宣佈數據庫的詳細信息 – Fabio
而在sitenote上:請不要再使用mysql擴展。它被正式棄用。您應該使用[PDO](http://www.php.net/PDO)或[MySQLi](http://www.php.net/MySQLi)來代替。 – Tularis