为什么连接到mySQL数据库的conn和查询不起作用?

时间:2019-02-19 12:50:17

标签: php mysql mysqli

我真的不知道为什么我尝试连接并从MySQL数据库中提取一些数据,但它不起作用。我有一个名为“ my_db”的数据库和一个名为“ men”的列;这是我的代码

$servername = "localhost";
$username = "myusername";
$password = "";
$db = "my_db";

$conn = new mysqli($servername, $username, $password, $db);

$sql="SELECT * FROM men where 'surname' = Smith";
$result = $conn->query($sql);

我要去哪里错了?

1 个答案:

答案 0 :(得分:0)

请尝试以下代码:

$servername = "localhost";
$username = "myusername";
$password = "";
$db = "my_db";

$conn = new mysqli($servername, $username, $password, $db);

$sql="SELECT * FROM men where surname = 'Smith'";
$result = $conn->query($sql);