To execute queries on the mysqli object, the query() method is called, to which the SQL command to be executed is passed:
$conn = new mysqli("localhost", "root", "password"); $conn->query(SQL command);
method query() returns true or false.
Create a database
The CREATE DATABASE command is used to create a database in MySQL
For example, lets create a testdb database:
$conn = new mysqli("localhost", "root", "password"); if($conn->connect_error){//check connection die("Error: " . $conn->connect_error); } // create testdb database $sql = "CREATE DATABASE testdb"; if($conn->query($sql)){ echo "Database is created"; } else{ echo "Database creating failed!" . $conn->error; } //stop the connection $conn->close();
Creating a table in a database. PHP OOP example
May 4, 2022