开始了。我对 PHP 还是很陌生,我正在尝试学习 PDO。我试图弄清楚为什么
$validStartYear=-1;
echo $listString; //$listString = 'WHERE a regexp "Nissan"'
$queryToPrep='SELECT a FROM b WHERE a regexp "Nissan" ORDER BY start_year asc LIMIT 1;';
$query = $newMysql->prepare($queryToPrep);
$query->execute();
echo '<br/><br/>';
print_r($query);
echo '<br/>';
$row=$query->fetch();
echo $row[0],'<br/>';
输出
a regexp "Nissan"
PDOStatement Object ( [queryString] => SELECT a FROM b WHERE a regexp "Nissan" ORDER BY start_year asc LIMIT 1; )
1971
尽管
$prepAgain='SELECT a FROM b WHERE ? ORDER BY a asc LIMIT 1;';
$query2= $newMysql->prepare($prepAgain);
$query2->bindParam(1, $listString, PDO::PARAM_STR);
$query2->execute();
echo '<br/>';
print_r($query2);
echo '<br/>';
$row2=$query2->fetch();
echo $row2[0];
输出
PDOStatement Object ( [queryString] => SELECT start_year FROM engine_kits WHERE ? ORDER BY start_year asc LIMIT 1; )
不返回任何值。我得到一个空数组,不管我有多大。语法似乎正确,但我错过了什么吗?