SQL 错误 #1064 - PHP 代码

SQL Error #1064 - PHP code

我只是在 PHP 的上下文中学习 SQL,我遇到了问题。 我做了这个代码:

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!!

不用写USE benutzer; 已通过 mysqli_connect

选择数据库

您还混用了 mysqlmysqli API。这些是完全不同的 APIs 并且 mysqlDEPRECATED.

您使用 mysqli_connect 连接,但您使用 mysql_query, 你能试试吗mysqli_query