mysql_create_db

mysql_create_db — Create a MySQL database

Version: (PHP 4, PHP 5)

Syntax: bool mysql_create_db  ( string $database_name [,resource $link_identifier])

Description: mysql_create_db() attempts to create a new database on the server associated with the specified link identifier.

database_name The name of the database being created.

link_identifier The MySQL connection. If the link identifier is not specified, the last link opened by mysql_connect() is assumed. If no such link is found, it will try to create one as if mysql_connect() was called with no arguments. If by chance no connection is found or established, an E_WARNING level error is generated.

Return Values: Returns TRUE on success or FALSE on failure.

# Example: MySQL create database example

<?php
$con = mysql_connect("localhost", "user", "password");
if (!$con) {
    die("Could not connect:" . mysql_error());
}

$sql = "CREATE DATABASE mydb"; if (mysql_query($sql, $con))       {     echo "Database my_db created successfullyn";       }        else {     echo "Error creating database:" . mysql_error() . "n";    } ?>

<?
    function mysql_create_db($database, $con = NULL)
      {
        $con = mysql_resolve_link($con);
        $query = "CREATE DATABASE $database";
        $result = msyqli_query($con
, $query);
        return (!$result) ? false : true;
    }

?>

Post Comment
Login to post comments