我正在尝试在php上创建一个通用方法/函数,它使用带有where子句的任何select语句。但是,有些事情是不对的。你能帮我个忙吗?
使用数据的示例:
DB inherit PDO class.
$db=new DB;
$db->select("SELECT count(*) FROM `login` WHERE Email='?'",
"papa1980@gmail.com");
这是功能
public function select($sqlString,...$bindParameters)
{
$stmt=$this->prepare($sqlString);
foreach($bindParameters as $key=>$bindParameter)
{
$stmt->bindParam(($key+1),$bindParameter);
echo '<pre>' . print_r($stmt, true) . '</pre>';
}
echo '<pre>' . print_r($bindParameters, true) . '</pre>';
if($stmt->execute())
{
echo "execution was succesful";
}
echo '<pre>' . print_r($stmt->fetchAll(), true) . '</pre>';
}
输出
PDOStatement对象
(
[queryString] =&gt; SELECT count(*)FROM login
WHERE Email ='?'
)
阵 ( [0] =&gt; papa1980@gmail.com )
执行是成功的
阵 ( [0] =&gt;排列 ( [count(*)] =&gt; 0 [0] =&gt; 0 ) )
为什么返回0?我用
SELECT count(*) FROM `login` WHERE Email='papa1980@gmail.com'
在mysql中,它返回1.我的PHP代码中有些东西不正确。
答案 0 :(得分:0)
功能正常,但是
SELECT count(*)FROM /* 0 */
{
"_id" : ObjectId("554a7dc35c5e0118072dd885"),
"title" : "Company Three Site",
"admins" : [
"personC",
"personD",
"personA",
"personB"
],
"email_address" : "company2plus1@mysite.com"
}
WHERE Email =?是错的,因为?不应该在''