0

I am trying to run an insert query from codeigniter by using the following code

$this->db->query($query);

but I am getting the following error:

Error Number: 1064

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 4

INSERT INTO order_bank 
    (creation_date, order_type, so_no, 
    material_no, description, order_qty, no_of_panels, 
    division, job_number, customer_group, sales_office, 
    sales_group, project_name, project_manager, 
    net_value_myr, credit_status, so_delivery_date, 
    order_delivery_date) 
VALUES ( '2013-07-01', 'ZTOR', 3058627219, 
    101900000000, 'SUPPLY, MODIFY, INSTALL TEST VCU', 
    1, 0, 'AIS (TSM)', 'SC139203J01', 'Industry', 
    'SEA', 'DOM', 'MELAKA', 
    'Phua Tiang Hai', 42954.55, '', '2013-07-11', 
    '2013-07-05');

Filename: C:\wamp\www\system\database\DB_driver.php
Line Number: 330

But when I am running the above query in phpmyadmin its working perfectly. Please help me in sorting out the issue

4

4 回答 4

4

使用 Codeigniter 提供的活动记录,会更安全、更简单!

http://ellislab.com/codeigniter/user-guide/database/active_record.html

例子:-

$this->db->set('description', $description);
$this->db->set('order_qty', $order_qty);
$this->db->set('no_of_panels', $no_of_panels);
$this->db->set('division', $division);
$this->db->set('job_number', $job_number);
$this->db->set('customer_group', $customer_group);
$this->db->set('sales_office', $sales_office);
$this->db->set('sales_group', $sales_group);
$this->db->set('project_name', $project_name);
$this->db->set('project_manager', $project_manager);
$this->db->set('net_value_myr', $net_value_myr);
$this->db->set('credit_status', $credit_status);
$this->db->set('so_delivery_date', $so_delivery_date);
$this->db->set('order_delivery_date', $order_delivery_date);
$this->db->insert('order_bank');

或者如果您的数据存储在数组中,那么您可以简单地运行

$this->db->insert('order_bank', $data);
于 2013-08-15T09:56:49.377 回答
2

您必须在控制器类或自动加载文件中加载数据库库。

在自动加载文件中:

$autoload['libraries'] = array('database');

或在控制器类中:

$this->load->library("database");
于 2013-08-16T07:00:17.090 回答
0

42954.55 必须是“42954.55”。忽略活动记录示例,因为这与问题无关,这就是此查询失败的原因。

于 2013-08-15T10:48:13.423 回答
-1

尝试这样的事情

$data = array(
   'user_id' => '$user_id' ,
   'photo_id' => '$photo_id' ,
   'album_id' => '$album_id'
);

$this->db->insert('photo_album', $data);
于 2014-12-03T07:39:41.467 回答