php CI架構插入一條或多條sql記錄樣本,cisql_PHP教程

來源:互聯網
上載者:User

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...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.