我正在使用php pdo包装器类
我收到以下错误
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1065 Query was empty' in C:\xampp\htdocs\mysite\include\SimplePDO.php:200 Stack trace: #0 C:\xampp\htdocs\mysite\include\SimplePDO.php(200): PDO->prepare('') #1 C:\xampp\htdocs\mysite\include\SimplePDO.php(244): SimplePDO->query(false, Array, true) #2 C:\xampp\htdocs\mysite\articles.php(57): SimplePDO->get_results(false) #3 {main} thrown in C:\xampp\htdocs\mysite\include\SimplePDO.php on line 200
包装类代码:
public function query( $query, $bindings = array(), $internal_call = false )
{
$this->counter++;
$this->c_query = $this->pdo->prepare( $query );
if( empty( $bindings ) )
{
$this->c_query->execute();
}
else
{
$this->c_query->execute( (array)$bindings );
}
//Alternate the response based on class internal vs. direct call to "query()"
if( $internal_call === true )
{
return $this->c_query;
}
elseif( $this->c_query && $this->lastid() )
{
return $this->lastid();
}
else
{
return false;
}
}
//end query()
public function get_results( $query, $bindings = array() )
{
return $this->query( $query, $bindings, true )->fetchAll();
}
//end get_results()
我正在尝试的查询如下:
$q1 = $database1->query( "SELECT * FROM sa_articleuploads_by_admin WHERE language=? ORDER BY article_upload_date AND article_subject ASC ", array( 'marathi' ));
$objTotalRS1 = $database1->get_results( $q1 );
$counts = 1;
$len = $database1->num_rows( $q1 );
if ($len !=0){
foreach ($objTotalRS1 as $data){
......////rest of my code
我查了一下语言专栏,我也检查了错字错误。但无法找到错误抛出的原因。
我在使用php版本5.6.15的XAMPP本地服务器上尝试此操作
您的帮助表示赞赏
答案 0 :(得分:0)
调用
$objTotalRS1 = $database1->get_results( $q1 );
只需调用query()方法,该方法期望$ q1成为您要执行的SQL语句。所以get_results应该做类似
的事情return $query->fetch();
这样就完成了准备查询(在查询方法中)并在get_results中获取结果的想法。