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 关于线性结构的问题:希望能从头到尾完整地帮我改一下,困扰我很久了
  • ¥20 设计一个二极管稳压值检测电路
  • ¥15 内网办公电脑进行向日葵
  • ¥15 如何输入双曲线的参数a然后画出双曲线?我输入处理函数加上后就没有用了,不知道怎么回事去掉后双曲线可以画出来
  • ¥50 WPF Lidgren.Network.Core2连接问题
  • ¥15 soildworks装配体的尺寸问题
  • ¥100 有偿寻云闪付SDK转URL技术
  • ¥30 基于信创PC发布的QT应用如何跨用户启动后输入中文
  • ¥20 非root手机,如何精准控制手机流量消耗的大小,如20M
  • ¥15 远程安装一下vasp