doumeng1143 2015-09-07 08:32
浏览 45
已采纳

当我重用(略微修改)查询时,是否必须重新绑定我的PDO参数?

Before I insert a row, I want to check for its existence, in order to avoid duplicates.

So, I

$pdo = ConenctToDatabase();

// Check for existence - don't add a duplicate
$sqlQuery = $pdo->prepare('SELECT campaign_id FROM campaigns WHERE (customer_id=:$customerId) AND (title=:campaignTitle) AND (description=:campaignDescription) AND (start_time=:startTimeStamp) AND (end_time=:endTimeStamp)');

$sqlQuery->bindParam(':customerId', $customerId, PDO::PARAM_INT);
$sqlQuery->bindParam(':campaignTitle', $campaignTitle);
$sqlQuery->bindParam(':campaignDescription', $campaignDescription);
$sqlQuery->bindParam(':startTimeStamp', $campaignTitle);
$sqlQuery->bindParam(':endTimeStamp', $endTimeStamp);

If it doesn't already exist, I want to reuse the PDO statement, changing the SELECT to an INSERT.

The INSERT takes identical parameters. Do I have to bind them again after the second prepare?

  • 写回答

1条回答 默认 最新

  • dqwh1219 2015-09-07 13:34
    关注

    In fact, if you only tried it yourself, you would find that there is no way to change a query in a statement. So, your assumption will fail even with making a "slight modification" to the query, not even making to the stage of "rebinding" values. There is no "second prepare" either. By calling prepare, you are creating a brand new statement that knows nothing of the others (a behavior is common for any other variable in PHP).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 r语言神经网络自变量重要性分析
  • ¥15 基于双目测规则物体尺寸
  • ¥15 wegame打不开英雄联盟
  • ¥15 公司的电脑,win10系统自带远程协助,访问家里个人电脑,提示出现内部错误,各种常规的设置都已经尝试,感觉公司对此功能进行了限制(我们是集团公司)
  • ¥15 救!ENVI5.6深度学习初始化模型报错怎么办?
  • ¥30 eclipse开启服务后,网页无法打开
  • ¥30 雷达辐射源信号参考模型
  • ¥15 html+css+js如何实现这样子的效果?
  • ¥15 STM32单片机自主设计
  • ¥15 如何在node.js中或者java中给wav格式的音频编码成sil格式呢