A data insertion test involves creating a separate database specifically for testing purposes, so as not to alter the production data. To perform this test, a script is used to insert data into this database. This script connects to the database and executes an SQL INSERT query to add the necessary data.
Here is an example of a PHP script that illustrates this process:
“`php
// Database Connection
$servername = “localhost”;
$username = “test”;
$password = “”;
$dbname = “testdb”;
$conn = mysqli_connect($servername, $username, $password, $dbname);
/ Connection Check
if (!$conn) {
die(“Connection failed: ” . mysqli_connect_error());
}
// Inserting data into the “users” table
$sql = “INSERT INTO users (name, email, phone) VALUES (‘testeur’, ‘testeur@example.com’, ‘1234567890’)”;
if (mysqli_query($conn, $sql)) {
echo “New record created successfully”;
} else {
echo “Error: ” . $sql . “
” . mysqli_error($conn);
}
// Closing the connection
mysqli_close($conn);
“`
This script establishes a connection to the database and then inserts dummy data into the “users” table. If successful, a message indicating the creation of a new record is displayed; otherwise, an error is reported. Finally, the connection to the database is closed to complete the process.