gpt4 book ai didi

php - 如何在mysql查询中写入字符串变量?

转载 作者:行者123 更新时间:2023-11-30 00:11:26 25 4
gpt4 key购买 nike

我想实现这个查询:

if(x=1){
$update = "close = '$date'";
}
else {
$update = "open = '$date'";
}
$query = "Update table1 set $update where id=100";
mysql_query($query);

但是我得到一个错误,Mysql无法执行查询?

最佳答案

   <?php
if($x==1){
$update = "close = '".$date."'";
}
else {
$update = "open = '".$date."'";
}
$query = "update table1 set $update where id=100";
mysql_query($query);
?>

关于php - 如何在mysql查询中写入字符串变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24007903/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com