php - mysql不能返回一行结果

标签 php mysql

我连接的是数据库,一个页面有很多内容,所以我只分享在php中没有返回值但在MySQL中有返回值的部分

这是代码;

$query = "SELECT firstname FROM users WHERE id = '17'";
$query_run = mysql_query($query);
$row = mysql_fetch_row($query_run);
echo $row[0]; 

最佳答案

Changing the code I shared first to this, solved the problem. Thanks to anyone who tried to help.

    $query = "SELECT firstname FROM users WHERE id = '17'";
    $query_run = mysqli_query($conn, $query);
    $row = mysqli_fetch_row($query_run);
    echo $row[0];

And made bit changes to the connect.inc.php which I also shared in comment.

<?php

$servername = "localhost";
$username = "root";
$password = "";
$dbname = "notsitesi";

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

if($conn->connect_error) {
die("Connection failed");
}

 ?>

关于php - mysql不能返回一行结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37624691/

相关文章:

php - symfony2以管理员用户身份访问私有(private)文件

java - 为什么可以在 PHP 中覆盖实例变量而在 Java 中不能?

php - 包含/要求 PHP 不工作

使用 PFK 的 MySQL View

php - 如何将 Facebook 页面帖子作为博客帖子拉入 WordPress?

php - JOIN 在 php mysql 中不起作用

mysql - SQL 两个表的左连接

java - MySQL 8.0.11 抛出 CLIENT_PLUGIN_AUTH is required

php - jsonObject.getString ("String in UTF8") 给出空白

mysql - UPDATE row ON UPDATE 触发器,多表条件