As we all know, PHP provides us with a function called mysql_query to create a new database.
To illustrate this, in the following example, we will create a database named "Tutorials" with the help of a PHP script -
<html> <head> <title>Creating MySQL Database</title> </head> <body> <?php $dbhost = 'localhost:3036'; $dbuser = 'root'; $dbpass = 'rootpassword'; $conn = mysql_connect($dbhost, $dbuser, $dbpass); if(! $conn ) { die('Could not connect: ' . mysql_error()); } echo 'Connected successfully<br />'; $sql = 'CREATE DATABASE TUTORIALS'; $retval = mysql_query( $sql, $conn ); if(! $retval ) { die('Could not create database: ' . mysql_error()); } echo "Database TUTORIALS created successfully</p><p>"; mysql_close($conn); ?> </body> </html>
The above is the detailed content of How can we create a new database using PHP script?. For more information, please follow other related articles on the PHP Chinese website!