Generic selectors
Exact matches only
Search in title
Search in content
Post Type Selectors

PHP and MySQ Creating database

1. Connect to MySQL server

Use the mysqli_connect function with server details, including hostname, username, password, and database name (the database to connect to, not the one to create).

$conn = mysqli_connect("localhost", "your_username", "your_password", "existing_database_name");

2. Define SQL statement

Write the CREATE DATABASE statement with the desired name for new database.

$sql = "CREATE DATABASE new_database_name;";

3. Execute the query

Use the mysqli_query function to execute the SQL statement on connection.

mysqli_query($conn, $sql)

4. Close the connection

Always remember to close the connection to your MySQL server with mysqli_close($conn).

mysqli_close($conn)