我正在运行脚本从网站获取订单并在数据库中插入其工作正常但我每次脚本运行时都会收到此错误 -
错误 - 严重性:警告 - > preg_match()期望参数2 字符串,给定的对象 C:\ xampp \ htdocs \ system \ database \ drivers \ mysqli \ mysqli_driver.php 202
错误 - 严重性:警告 - > mysqli_query()期望参数2到 是字符串,对象给定 C:\ xampp \ htdocs \ system \ database \ drivers \ mysqli \ mysqli_driver.php 179
错误 - 严重性:警告 - > preg_match()期望参数2 字符串,给定对象C:\ xampp \ htdocs \ system \ database \ DB_driver.php 622
错误 - 严重性:警告 - > mysqli_num_rows()需要参数1 是mysqli_result,null给出 C:\ xampp \ htdocs \ system \ database \ drivers \ mysqli \ mysqli_result.php 37
这是我的代码
public function insert_orders($data_orders) {
foreach($data_orders as $key=>$value){
$order_id=trim($value['order_id']);
$amount_paid=trim($value['amount_paid']);
$query = $this->db->query("SELECT * FROM orders WHERE order_id='".$order_id."' AND amount_paid LIKE '".$amount_paid."'");
if ($query->num_rows > 0) {
unset($data_orders[$key]);
}
}
if(count($data_orders)==0) return;
$this->db->insert_batch('orders', $data_orders);
}
我看不出有任何问题,但请你查一下,让我知道我在哪里弄错了?
我正在使用codeigniter。
数据库设置 -
$db['default']['dbdriver'] = 'mysqli';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;
答案 0 :(得分:0)
将num_rows
设为num_rows()
if ($query->num_rows() > 0)