The Web Blinders logo

Programming

PHP MySqli Inserting Multiple Records at once example

<?php
$mysqli = new mysqli("localhost","root","","your_db",3306);

// Our table
// CREATE TABLE names(id int,first_name varchar(45),last_name varchar(45));

$qry=<<<QUERY
INSERT INTO 
names(id,first_name,last_name)
VALUES
    (1,"Thomas","Shelby"),
    (2,"Joe","McMillan"),
    (3,"Bruce","Robertson")
QUERY;

// That's it ...You inserted multiple records at once
$mysqli->query($qry);

// Let's check
$qry="SELECT * FROM names";
$result = $mysqli->query($qry);

while ($row = $result->fetch_assoc()) {
    print_r($row);
}

?>

ALTERNATE TITLES

Insert two rows php mysqli

Inserting multiple rows php mysqli

how to insert multiple rows mysql php

php mysql insert statement example

php mysql tutorials
Insert statement with multiple values php mysql

Php tutorials

php mysql tutorials

Need developers ?

if so, send a message.

thewebblinders@gmail.com

More Programming from our blog

SEARCH FOR ARTICLES