How can we create a database using PHP and MySQL?
TechnicalSenior php developerPHP DeveloperMid PHP DeveloperTo create a database using PHP and MySQL, I would first establish a connection to the MySQL server using the mysqli_connect() function. Then, I would execute a SQL query with mysqli_query() to create the database. For example:
- Connect: $conn = mysqli_connect('localhost', 'username', 'password');
- Create: mysqli_query($conn, 'CREATE DATABASE my_database');
This approach is straightforward, but I ensure to handle errors effectively by checking the connection and query results.