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");
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 R语言卸载之后无法重装,显示电脑存在下载某些较大二进制文件行为,怎么办
  • ¥15 java 的protected权限 ,问题在注释里