【问题标题】:Why can't I get data from SQL row using PHP prepared statements?为什么我不能使用 PHP 准备语句从 SQL 行获取数据?
【发布时间】:2020-08-27 15:33:57
【问题描述】:

连接良好。我可以插入数据库,并通过检查结果是否 > 0 来检查是否存在行,但我无法选择行数据。正在测试的 $email 在数据库中。 例 1。

require 'connection/connection.php';
$email = "sample@sample.com";

$sql = "SELECT * FROM users WHERE user_email=?"; // SQL with parameters
$stmt = $conn->prepare($sql); 
$stmt->bind_param("s", $email);
$stmt->execute();
$result = $stmt->get_result(); // get the mysqli result
$user = $result->fetch_assoc(); // fetch data  
echo $user['user_name'];

例如。 2

$email = "james@james.com";
$sql = "SELECT * FROM users WHERE user_email=?";
$stmt = mysqli_stmt_init($conn);
mysqli_stmt_bind_param($stmt, "s", $email);
mysqli_stmt_execute($stmt);

在每一行之后插入一个回显之后,这就是它所能得到的。如果 echo 语句放在下一行之后,它将不会出现。

$result = mysqli_stmt_get_result($stmt);
if ($row = mysqli_fetch_assoc($result)) {
    $_SESSION['active_user_id'] = $row['user_id'];
} else {
    header("Location: https://example.com/");
    exit();
}

【问题讨论】:

    标签: php mysqli prepared-statement cpanel


    【解决方案1】:

    问题已通过 cPanel 修复。我不得不从“mysqli”切换到“nd_mysqli”。这立即解决了问题。

    我在这里找到了执行此操作的说明https://www.plus2net.com/php_tutorial/mysqli_mysqlnd.php

    我希望这可以帮助其他有同样问题的人。

    【讨论】:

      猜你喜欢
      • 2015-05-16
      • 1970-01-01
      • 2016-04-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多