duanjian3920 2015-05-05 04:14
浏览 44
已采纳

PHP / PDO连接到Mysql,但查询似乎没有执行

Hello Stack Overflow! Im trying to connect to a database and update a certain set of records dependent on the information sent to the web server. When I execute the PHP page and get a result of no errors, nothing updates on the database. As if the query did not even execute. Also I can manually execute it, it works fine like you would expect. The PDO driver connection is setup correctly and does not declare an error.

My Code:

(The Connection Information is declared in a separate database.php file, as well as the table names. This is only the part of the code that interacts on the part that malfunctions.)

<? php
include "database.php";
$conn = new MySQLi($host, $username, $password, $db_name);

if ($conn - > connect_error) {
  die("Connection failed: ".$conn - > connect_error);
}
$conp = new PDO("mysql:host=$host;port=3306;dbname=$db_name", $username, $password);
$conp - > setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$conp - > setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
    try {
      $sql = null;
      $sql1 = $conp - > prepare("UPDATE `".$tbl_bans_name.
        "` SET `resolved`='1' WHERE `Date`=':date' AND `Reason`=':reason'");
      $sql1 - > bindParam(':date', $date);
      $sql1 - > bindParam(':reason', $reason);
      if ($sql1 - > execute()) {
        echo "good";
      }
      $sql1 = null;
    } catch (PDOException $e) {
      print_r($e);
    }
    //$execute = Mysqli_query($conn, $sql1);
    //mysqli_close($conn);

?>

Any and all help is appreciated! I would be grateful because this problem has been troubling me for the past few hours.

</div>
  • 写回答

1条回答 默认 最新

  • duanlu1279 2015-05-05 04:21
    关注

    I think you should correct this row, by removing ' around :date & :reason - like this:

     "` SET `resolved`='1' WHERE `Date`=:date AND `Reason`=:reason");
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了