所以我正在重建从mysql到PDO的链接生成功能,我遇到了问题。
$sth = $resDB->prepare("SELECT count(*) FROM downloads WHERE downloadkey = '{$strKey}' LIMIT 1");
$arrCheck = $sth->fetchAll();
if($arrCheck['count(*)']){
//key already in use
return createKey();
}else{
//key is OK
return $strKey;
}
在此行之前一切顺利:if($arrCheck['count(*)'])
我收到如下错误:Undefined index: count(*)
我只是不知道如何将该行更改为PDO。你能救我吗?
答案 0 :(得分:3)
使用别名来引用列
SELECT count(*) as cnt FROM ...
$arrCheck["cnt"]
答案 1 :(得分:3)
使用别名
尝试此操作$sth = $resDB->prepare("SELECT count(*) as count FROM downloads WHERE downloadkey = '{$strKey}' LIMIT 1");
$arrCheck = $sth->fetchAll();
if($arrCheck['count']){