2016-09-20 60 views
0

我與我的網站,數據庫和連接是成功的,但是當我試圖從數據庫表中獲取值我得到這個錯誤:從表錯誤的mysqli獲取值

Warning: mysql_query(): Access denied for user ''@'localhost' (using password: NO) in /home/username/public_html/root/connecti.php on line 17

Warning: mysql_query(): A link to the server could not be established in /home/username/public_html/root/connecti.php on line 17

連接成功

第17行:

$sql = mysql_query("SELECT * FROM 'tblusers' LIMIT 0, 30"); 
+0

該用戶是否具有對數據庫表的寫入權限? –

+1

給出了更多的源代碼,至少17個第一行connecti.php –

+0

看起來像你的連接線沒有「用戶名」和「密碼」參數,你沒有一個真正的成功連接[mysqli_connect](http:// '$ link = mysqli_connect(「127.0.0.1」,「my_user」,「my_password」,「my_db」);' –

回答

0

我的猜測是,您使用mysqli_connect() stablish連接,但然後嘗試使用mysql_query()逃脫它。按照文檔:

mixed mysql_query (string $query [, resource $link_identifier = NULL ])

link_identifier 

The MySQL connection. If the link identifier is not specified, the last link opened by mysql_connect() is assumed. If no such link is found, it will try to create one as if mysql_connect() had been called with no arguments. If no connection is found or established, an E_WARNING level error is generated.

如果您檢查手冊頁mysql_connect(),你會看到它可能試圖使用你沒有設置系統範圍的憑據。

你不能混合你喜歡的數據庫擴展。停止使用傳統擴展並堅持使用mysqli。

+0

所以我有點想通了,我改變了MySQL到mysqli並使用mysqli_connect。 現在我的問題是,在填充表格時,我沒有從數據庫表中獲取任何值。 (連接成功) 查詢: $ sql = mysqli_query($ conn,「SELECT'firstname'從'tblusers'WHERE 1」); 我也讀了一些關於mysqli_fetch的信息,也許這是這個問題的答案? – Jason

0

看看你SELECT查詢,你會看到,引述周圍的單引號表名是因爲DB連接問題gine然後將其視爲字符串文字而不是DB對象。

你的意思是使用backtique

"SELECT * FROM `tblusers` LIMIT 0, 30"