数据库查询失败。无法找到错误

时间:2017-11-09 13:15:19

标签: php mysql database-connection

我成功连接到数据库,但随后出现以下错误:

  

致命错误:未捕获错误:在[我的路径]中调用未定义的函数mysqli_query():17

这是代码:

<?php
$servername = "my_servername";
$username = "my_username";
$password = "my_password";
$base = "my_database";

// Create connection
$conn = new mysqli($servername, $username, $password, $base);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
?>
<?php
$result = mysqli_query("SELECT name FROM links WHERE id =1");
  echo $result;
?>

1 个答案:

答案 0 :(得分:1)

建立连接后,您可以像这样使用它(OOP MySQLi):

<?php
$query="SELECT name FROM links WHERE id =1";
$result = $conn->query($query);

要访问您需要先获取的数据。所以你这样:

while($row = $result->fetch_assoc()) {
    // do something with your results
    echo $row['name'];
}