php - PDO: Invalid parameter number: mixed named and positional parameters -


i have come across warning i've not seen before:

warning: pdostatement::execute() [pdostatement.execute]: sqlstate[hy093]: invalid parameter number: mixed named , positional parameters in...

referring following pdo query (have simplified function ease of reading):

$offset = 0; $limit = 12; function retrieve_search_posts($searchfield, $offset, $limit){           $where = array();          $words = preg_split('/[\s]+/',$searchfield);          array_unshift($words, '');         unset($words[0]);          $where_string = implode(" or ", array_fill(0,count($words), "`post_title` ?"));          $query = "                                 select  p.post_id, post_year, post_desc, post_title, post_date, img_file_name, p.cat_id                                    mjbox_posts p                                 join    mjbox_images                                 on      i.post_id = p.post_id                                         , i.cat_id = p.cat_id                                         , i.img_is_thumb = 1                                         , post_active = 1                                 $where_string                                 order post_date                                 limit :offset, :limit                                 desc";         $stmt = $dbh->prepare($query);          foreach($words $index => $word){             $stmt->bindvalue($index, "%".$word."%", pdo::param_str);         }         $stmt->bindparam(':offset', $offset, pdo::param_int);         $stmt->bindparam(':limit', $limit, pdo::param_int);         $stmt->execute();          $searcharray = $stmt->fetchall(pdo::fetch_assoc);          return $searcharray;     } 

the function , pdo query works fine without offset , limit variables included in query. might causing warning?

thanks

change

limit :offset, :limit 

to

limit ?, ? 

and

$stmt->bindparam(':offset', $offset, pdo::param_int); $stmt->bindparam(':limit', $limit, pdo::param_int); 

to:

$stmt->bindvalue($index+1, $offset, pdo::param_int); $stmt->bindvalue($index+2, $limit, pdo::param_int); 

Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -