php - 当我更改数据库时,准备好的语句失败

标签 php mysql database

问题

今天早上我在更新数据库时遇到了一些奇怪的事情。我在数据库中执行了排序规则更改,将其从 latin1 更改为 uft8。然而,我的查询突然在我的 table 上失败了。经过一些调试(即使使用原始设置重建表,但没有这样的效果)并收到 500 个内部错误,我意识到它与 准备好的语句有关,所以我把它撕掉了,并将其替换为常规的mysqli_query,并且令人惊讶的是它有效。所以现在我想知道,我的准备语句是否一直都是错误的,或者是因为数据库的更改而失败。

设置

这是当前设置的表。我将其改回拉丁语(及其 innoDB),但当我将所有内容改回原始设置(这就是现在的样子)时,它没有给我想要的结果

database setup

代码

原始代码是这样的,在更改之前它工作正常

    require_once '../db/dbControl.php';

    $id = mysqli_real_escape_string($con,$_GET["id"]);  
    $sql = "SELECT  *
            FROM project
            WHERE   project.ProjectId = ? ";    
  $stmt1 = mysqli_prepare($con, $sql);
  mysqli_stmt_bind_param($stmt1,'i',$id);
  mysqli_stmt_execute($stmt1);
  mysqli_stmt_bind_result($stmt1,$ProjectId,$ProjectTitel,$ProjectOmschrijving, $ProjectOmschrijving,$ProjectDatum,$ProjectClient,$ProjectUrl);
  while (mysqli_stmt_fetch($stmt1)){ 

  the code itself of the page

  }

所以现在我只是使用常规的 mysqli_query 来使其工作

require_once '../db/dbControl.php';

id = mysqli_real_escape_string($con,$_GET["id"]);   
$sql = "SELECT  *
        FROM project
        WHERE   project.ProjectId = '". $id ."'";   
$result = mysqli_query($con,$sql);
while($rows=mysqli_fetch_array($result)){
    $ProjectId = $rows['ProjectId'];
    $ProjectTitel = $rows['ProjectTitel'];
    $ProjectExpertise = $rows['ProjectExpertise'];
    $ProjectOmschrijving = $rows['ProjectOmschrijving'];
    $ProjectDatum = $rows['ProjectDatum'];
    $ProjectClient = $rows['ProjectClient'];
    $ProjectUrl = $rows['ProjectUrl'];

    the code itself of the page

  }

我有点困惑(也许我在这里忽略了一些东西,因为专注于一点代码),但它只发生在项目表上。我对照涉及读数的代码对其进行了检查,并且它们与准备好的语句一起工作得很好。

希望有人能发现我没发现的东西

最佳答案

无法告诉你发生了什么,但这里有两个想法。

The prepared statement execution consists of two stages: prepare and execute. At the prepare stage a statement template is sent to the database server. The server performs a syntax check and initializes server internal resources for later use.

A prepared statement can be executed repeatedly. Upon every execution the current value of the bound variable is evaluated and sent to the server. The statement is not parsed again. The statement template is not transferred to the server again.

也许这就是发生的情况,可能是在您更改为 utf8 后准备好的语句从未重置。

Every prepared statement occupies server resources. Statements should be closed explicitly immediately after use. If not done explicitly, the statement will be closed when the statement handle is freed by PHP.

Using a prepared statement is not always the most efficient way of executing a statement. A prepared statement executed only once causes more client-server round-trips than a non-prepared statement. This is why the SELECT is not run as a prepared statement above.

也许服务器内存(已经/曾经)已满?

Tekst 来自: http://php.net/manual/en/mysqli.quickstart.prepared-statements.php

关于php - 当我更改数据库时,准备好的语句失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28697028/

相关文章:

PHP 与 MySQL 查询未返回预期结果

php - PHP 命名空间名称中的有效字符是什么?

php - 使用 MySQL 结果更改 UITextField(xcode 项目)

mysql - Prestashop SQL 管理器 GROUP BY 日期

php - 如何在查询中选择特定值加上额外的随机值?

javascript - 为什么Chrome在加载后将我的页面称为XHR,并执行MySQLi插入两次?

php - 如何使用 WP_Query 对 post_IDs 键而不是值进行排序

mysql - 我的 sql 查询有些奇怪

php - 如果变量在数据库中,则停止-如果变量不在数据库中-则输入它

php - MYSQL php 几个表不工作