我有以下代码:
$sth = $dbh->prepare('SELECT COUNT(*) as size FROM `users` WHERE uid = :uidVal');
$sth->bindValue(':uidVal', $_POST['uid'], PDO::PARAM_INT);
// $_POST['uid'] == 2147483647
$sth->execute();
$size = $sth->fetchAll();
print_r($size);
print_r()返回:
数组([0] =>数组([size] => 0 [0] => 0))
但这是我的数据库(mysql)
我不明白为什么我的COUNT(*)
会返回0,通常应该返回3?
编辑(根据评论)
这是我在select语句之后的代码:
$stmt = $dbh->prepare("INSERT INTO `users` (uid, uname) VALUES (?, ?)");
$stmt->bindParam(1, $uid);
$stmt->bindParam(2, $name);
// insertion d'une ligne
$name = $_POST['uname'];
$uid = $_POST['uid'];
$stmt->execute();
为什么在我的数据库中,uid值为2147483647
,而$ _POST中的uid值为10152434954117198
答案 0 :(得分:1)
我的数据库配置的uid值很大:
10152434954117198
是一个长整数
答案 1 :(得分:-1)
试试这段代码。
$sth = $dbh->prepare('SELECT COUNT(*) as size FROM `users` WHERE uid = ?');
$sth->bindValue(1, $_POST['uid']);
// $_POST['uid'] == 2147483647
$sth->execute();
$size = $sth->fetchAll();
print_r($size);
或者你可以试试这个
$sth = $dbh->prepare('SELECT COUNT(*) as size FROM `users` WHERE uid = :uidVal');
// $_POST['uid'] == 2147483647
$sth->execute([
"uidVal" => $_POST['uid']
]);
$size = $sth->fetchAll();
print_r($size);