PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
Copy Clear
Copy Format Clear
<?php // Using the pre-defined instance of PDO ($pdo) and mysqli ($mysqli) global $pdo, $mysqli; // Step a: Connect to the MySQL server $pdo->query("CREATE DATABASE IF NOT EXISTS CourseDB"); // Step b: Select the created database $pdo->query("USE CourseDB"); // Step c: Create a table named "student" using mysqli $mysqli->query("CREATE TABLE IF NOT EXISTS student ( id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY, Name VARCHAR(30) NOT NULL, Age INT(3) NOT NULL )"); // Step d: Insert records into the table using mysqli $mysqli->query("INSERT INTO student (Name, Age) VALUES ('Ahmed', 20), ('Hamid', 21)"); // Step e: Update the age of the record with id=2 using mysqli $mysqli->query("UPDATE student SET Age=23 WHERE id=2"); // Step f: Delete records with "Ahmed" as the name using mysqli $mysqli->query("DELETE FROM student WHERE Name='Ahmed'"); echo "Database manipulations completed successfully."; ?>
Show:  
Copy Clear