Current I'm trying to query a COUNT(*) using user input, so I want to prepare it, but when I do it there are no response, also I made using this: Row count with PDO as example, (prepare and query) but they both seems to doesn't work. Why? theres no reason...
当前我正在尝试使用用户输入查询COUNT(*),所以我想准备它,但是当我这样做时没有响应,我也使用了这个:以PDO为例的行数,(准备和查询) )但它们似乎都不起作用。为什么?没有理由......
$count = $con->query("SELECT COUNT(*) FROM $table WHERE senha='$senha' AND var='{$ar[$i]}'")->fetchColumn();
if($count!=0){
$q = $con->prepare("UPDATE $table SET value=':value' WHERE senha=':senha' AND var=':var'");
$q->execute(array(':senha' => $senha, ':value' => $ar[$i+1], ':var' => $ar[$i]));
}else{
$q = $con->prepare("INSERT INTO $table (id,senha,var,value) VALUES (NULL, ':senha', ':var', ':value')");
$q->execute(array(':senha' => $senha, ':var' => $ar[$i], ':value' => $ar[$i+1]));
}
When I were using his first example (using prepare not query passing values using array) didn't work at all, the query one return a number but does not work the if
(update
or insert
) part I've tried a bunch of things and outputs, nothing worked...
当我使用他的第一个例子(使用prepare not query使用数组传递值)根本不起作用时,查询返回一个数字但不起作用if(更新或插入)部分我尝试过一堆东西和输出,什么都没有...
1 个解决方案
#1
3
You should not include single quote when you use parameters bind with PDO. so correct your UPDATE and INSERT query to followings:
使用参数bind与PDO时,不应包含单引号。所以更正你的UPDATE和INSERT查询如下:
$q = $con->prepare("UPDATE $table SET value=:value WHERE senha=:senha AND var=:var");
and
和
$q = $con->prepare("INSERT INTO $table (id,senha,var,value) VALUES (NULL, :senha, :var, :value)");
#1
3
You should not include single quote when you use parameters bind with PDO. so correct your UPDATE and INSERT query to followings:
使用参数bind与PDO时,不应包含单引号。所以更正你的UPDATE和INSERT查询如下:
$q = $con->prepare("UPDATE $table SET value=:value WHERE senha=:senha AND var=:var");
and
和
$q = $con->prepare("INSERT INTO $table (id,senha,var,value) VALUES (NULL, :senha, :var, :value)");