MySQL - Create Database MYSQL
- MySQL Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- Drop MySQL Database
- Selecting MySQL Database
- MySQL - Data Types
- Create MySQL Tables
- Drop MySQL Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - WHERE Clause
- MySQL - UPDATE Query
- MySQL - DELETE Query
- MySQL - LIKE Clause
- MySQL - Sorting Results
- Using MySQl Joins
- MySQL - Regexps
- MySQL - Transactions
- MySQL - ALTER Command
- MySQL - INDEXES
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- Using MySQL Sequences
- MySQL - Handling Duplicates
- MySQL - and SQL Injection
- MySQL - Database Export
MySQL - Create Database
Create a Database using PHP Script
PHP uses mysql_query function to create or delete a MySQL database. This function takes two parameters and returns TRUE on success or FALSE on failure.
Example
The following example to create a database −
<html>
<head>
<title>Creating MySQL Database</title>
</head>
<body>
<?php
$dbhost = 'localhost:3036';
$dbuser = 'root';
$dbpass = 'rootpassword';
$conn = mysql_connect($dbhost, $dbuser, $dbpass); //$conn holds connection referance
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\n";
mysql_close($conn);
?>
</body>
</html>