本文介绍了错误:绑定变量的数量与令牌的数量不匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我只想在db(mySQL)中没有对应关系的情况下进行插入,但是他让我不是该语句.这是代码段
I want to make an insert only if there's no correspondence in the db (mySQL) but he makes me not the statement. Here's the snippet
if ($sql->rowCount() > 0) {
echo 'Non inserisci';
} else {
echo 'Inserisci';
$db->beginTransaction();
echo 'Ciao3';
$sql = $db->prepare("INSERT INTO contatti (nome,cognome) VALUES (?,?)") or die('Ciao2');
echo 'Ciao4';
$sql->execute(array($_POST['nome'],$_POST['cognome']));
echo 'Ciao5';
$db->rollBack();
}
SELECT在哪里
$db->beginTransaction();
$sql = $db->prepare("SELECT * FROM contatti WHERE nome = ? AND cognome = ? WHERE nome = ? AND cognome = ?") or die ('Ciao1');
$sql->execute(array($_POST['nome'],$_POST['cognome']));
$db->rollBack();
你能解释一下哪里出问题了吗?
Can you explain me where's the fault?
推荐答案
错误出在算术中
让我们计数令牌:
SELECT * FROM contatti WHERE nome = ? // one
AND cognome = ? // two
WHERE nome = ? // three
AND cognome = ? // four
现在让我们计算绑定变量的数量:
now let's count number of bound variables:
array($_POST['nome'], // one
$_POST['cognome']) // two
4显然不等于2.这就是问题
4 is apparently not equal to two. that's the problem
这篇关于错误:绑定变量的数量与令牌的数量不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!