2015-01-04 108 views
-1

我只是學習PHP的上下文中的SQL,我有問題。 我做了這個代碼:SQL錯誤#1064 - PHP代碼

error_reporting(E_ALL); 
define ('MYSQL_HOST',  'localhost'); 
define ('MYSQL_BENUTZER', 'dvd'); 
define ('MYSQL_KENNWORT', 'abc'); 
define ('MYSQL_DATENBANK', 'benutzer'); 

#establish connection 
$db_link = mysqli_connect (
       MYSQL_HOST, 
       MYSQL_BENUTZER, 
       MYSQL_KENNWORT, 
       MYSQL_DATENBANK 
       ); 


$abfrage = "USE benutzer; SELECT `code`, `used` FROM `keys` WHERE `code` LIKE '$key'"; 
$ergebnis = mysql_query($abfrage); 
$row = mysql_fetch_object($ergebnis) 
OR die("Error: $ergebnis <br>".mysql_error()); 

我想有一個時間密鑰的系統和釋我混帳的數據,如果他們已經使用尋找。 有了這個代碼,PHP顯示我的錯誤:

Deprecated: mysql_query(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in C:\xampp\htdocs\dvds\administration\auth.php on line 8 
Warning: mysql_fetch_object(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\dvds\administration\auth.php on line 9 

Error: 
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SELECT `key`, `used` FROM `keys` WHERE `key` LIKE 'KjAvkSpUwJCdNjfTEDfRDUrVmGXBH' at line 1* 

Please help me!! 
+0

的mysql_query只接受一次一個查詢時,您已經確定在連接數據庫,取出使用benutzer,拋開過時的功能 – Mihai

+0

請使用mysqli_query。所有的mysql函數都被棄用,請使用mysqli代替 – Mramaa

+0

MySQLi:http://php.net/manual/en/book.mysqli.php PDO:http://php.net/manual/en/book.pdo.php – sodawillow

回答

0

有沒有必要寫USE benutzer; 數據庫通過mysqli_connect

已被選中您也是混合mysqlmysqli API的。這些是完全不同的API,並且mysqlDEPRECATED

0

您與mysqli_connect連接,但您使用的mysql_query, 可以嘗試mysqli_query

+0

好的,謝謝我會嘗試。 – Microgamer

+0

您必須將所有mysql命令轉換爲mysqli。例子:HTTP://php.net/manual/en/mysqli-result.fetch-object.php –