【问题标题】:How can Split PDO query based on the condition in PHP .I want to execute only part of query and another part to be executed based on the php condition如何根据 PHP 中的条件拆分 PDO 查询。我只想执行部分查询,另一部分根据 php 条件执行
【发布时间】:2018-04-28 08:34:30
【问题描述】:
  ##  I want to Convert this Mysqli code to the Pdo 

## 这是我根据条件拆分查询的 Mysqli 代码 我想在 PDO 中做到这一点

    $query="UPDATE sitetext SET text1 = '$sitetext', email = '$email'";
    if(isset($logo))
     {
       $query.=",logo='$logo' WHERE id = 1";
     }
   else
   {
      $query.=" WHERE id = 1";
    }
     $result=mysqli_query($conn,$query);

【问题讨论】:

  • 你试过了吗?发生了什么?
  • mysqli != pdo (-;

标签: php mysql mysqli pdo


【解决方案1】:

只需使用 PDO::exec 更改 mysqli_exec ?

$query="UPDATE sitetext SET text1 = '$sitetext', email = '$email'";

if(isset($logo))
{
   $query.=",logo='$logo' WHERE id = 1";
}
else
{
   $query.=" WHERE id = 1";
}

$result= $PDO_Object->exec($query);

【讨论】:

  • 谢谢它的工作
猜你喜欢
  • 1970-01-01
  • 2019-11-18
  • 1970-01-01
  • 2019-01-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-12-11
相关资源
最近更新 更多