<?PHP$dbhost= ' localhost:3306 ';$dbuser= ' Root ';$dbpass= ' ';$conn=mysql_connect($dbhost,$dbuser,$dbpass);if(!$conn ){ die(' Could not connect: '.Mysql_error());}Echo' Connected successfully<br/> ';//Deleting a database/*$sql = ' DROP database tutorials '; $retval = mysql_query ($sql, $conn), if (! $retval) {die (' Could not delete database : ‘ . Mysql_error ());} echo "Database tutorials deleted successfully\n";*///Create a database$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);?>
PHP uses the Mysql_query function to create or delete MySQL databases.
The function has two parameters, returns TRUE on successful execution, or FALSE.
Grammar
BOOL mysql_query( sql,);
Parameters |
Description |
Sql |
Necessary. Specifies the SQL query to send. Note: The query string should not end with a semicolon. |
Connection |
Optional. Specifies the SQL connection identifier. If not specified, the previous open connection is used. |
PHP Create Delete Database