作为这些事情的绝对初学者,我陷入困境:我需要构建一个查询来从3个表中删除所有出现的字符串,例如
$sql = "UPDATE table_1, table_2, table_3 SET column=REPLACE(column, '$string', '')";
如何构建准备好的语句来执行此操作?像
这样的东西$sql = "UPDATE table_1, table_2, table_3 SET column=:column";
$q = $dbh->prepare($sql);
$q->execute(array(':column'=>"REPLACE(column, '$string', '')"));
显然不起作用。
答案 0 :(得分:1)
运行三个查询。在单个查询中没有理智的方法。
就准备好的语句而言,您需要在查询中包含REPLACE()
函数,而不是在占位符中:
$q = $dbh->prepare("UPDATE table SET column = REPLACE(column, :string, '')");
$q->execute([ ':string' => $string ]);