MySQL Create Database
Since PHP 4.3, mysql_create_db() function is deprecated. Now it is recommended to use one of the 2 alternatives.
- mysqli_query()
- PDO::__query()
PHP MySQLi Create Database Example
Example
- <?php
- $host = 'localhost:8080';
- $user = '';
- $pass = '';
- $conn = mysqli_connect($host, $user, $pass);
- if(! $conn )
- {
- die('Could not connect: ' . mysqli_connect_error());
- }
- echo 'Connected successfully<br/>';
-
- $sql = 'CREATE Database mydb';
- if(mysqli_query( $conn,$sql)){
- echo "Database mydb created successfully.";
- }else{
- echo "Sorry, database creation failed ".mysqli_error($conn);
- }
- mysqli_close($conn);
- ?>
Output:
Connected successfully
Database mydb created successfully.