How to add multiple data to a MySQL database. PHP OOP exampl... open

How to add multiple data to a MySQL database. PHP OOP example

Approved. Code works!
This is exactly the working code that is verified by the moderator or site administrators
Tested: PHP 5.6 +

For example, we have added a users table with three columns id, name, age with the following definition:

CREATE TABLE Users (id INTEGER AUTO_INCREMENT PRIMARY KEY, name VARCHAR(30), age INTEGER)

The INSERT command is used to add data to MySQL:

//connect to our test database
$conn = new mysqli("localhost", "root", "password", "testdb");

//check connection on errors
if($conn->connect_error){
    die("Error" . $conn->connect_error);//return our errors
}

//add data to our tabble
$sql = "INSERT INTO Users (name, age) VALUES 
            ('Earl', 33), 
            ('Homer', 24), 
            ('Igor', 25)
            ";


if($conn->query($sql)){
    echo "Data sended";
} else{
    echo "Error: " . $conn->error;
}


$conn->close();
0

More

Leave a Reply

Your email address will not be published. Required fields are marked *

How many?: 22 + 22

lil-code© | 2022 - 2024
Go Top
Authorization
*
*
Registration
*
*
*
*
Password generation