php CI框架插入一条或多条sql记录示例,cisql
1、插入一条记录
$data = array(
'title' => 'My title' ,
'name' => 'My Name' ,
'date' => 'My date'
);
$this->db->insert('mytable', $data);
// Produces: INSERT INTO mytable (title, name, date) VALUES ('My title', 'My name', 'My date')
2、插入多条记录
$data = array(
array(
'title' => 'My title' ,
'name' => 'My Name' ,
'date' => 'My date'
),
array(
'title' => 'My title1' ,
'name' => 'My Name1' ,
'date' => 'My date1'
)
);
$this->db->insert_batch('mytable', $data);
// Produces: INSERT INTO mytable (title, name, date) VALUES ('My title', 'My name', 'My date'),('My title1', 'My name1', 'My date1')
怎使用一条SQL语句,插入多条记录?
用insert 和select 组合语句
例子如下:
数据插入Sales表:
INSERT INTO Sales(EmployeeID,ProductID,SupplierID,CustomerID,
OrderDate,UnitPrice,Total,Quantity,Discount)
SELECT e.EmployeeID, p.ProductID, s.SupplierID,
c.CustomerID, o.OrderDate, od.UnitPrice,
od.Quantity*od.UnitPrice*(1.0-od.Discount)Total,
Od.Quantity, od.Discount
from Orders o,[Order Details] od, Employees e,
Products p, Suppliers s, Customers c
where (o.OrderID = od.OrderID) and
(o.EmployeeID = e.EmployeeID) and
(o.CustomerID = c.CustomerID) and
(od.ProductId = p.ProductID) and
(p.SupplierID = s.SupplierID);
PHP+mysql 一条信息里的同一字段怎插入多条记录?比如有多张图片地址
简单例子看下你就明白了
insert into news (type_id,userid) values ('5','8'),('6','10'),('11','55');
id如果是主键的话,插入的时候可以不用写
http://www.bkjia.com/PHPjc/852376.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/852376.htmlTechArticlephp CI框架插入一条或多条sql记录示例,cisql 1、插入一条记录 $data = array('title' = 'My title' ,'name' = 'My Name' ,'date' = 'My date');$this-db-insert('mytable...
本条技术文章来源于互联网,如果无意侵犯您的权益请点击此处反馈版权投诉
本文系统来源:php中文网