How To Create a New Database


How To Create a New Database? - MySQL FAQs - PHP Connections and Query Execution



A database in a MySQL server is a logical container used to group tables and other data objects together as a unit. If you are a the administrator of the server, you can create a new databases using the CREATE DATABASE statements with MySQL client interface programs.

If you want to create a new database with a PHP script, you can still use deprecated function, mysql_create_db(). But it's better use the mysql_query($sql,$con) function to create new databases. The tutorial exercise below shows you how to create a database called "fyi":

  $con = mysql_connect('localhost:8888', 'dev', 'iyf');
  $sql = 'CREATE DATABASE fyi';
  if (mysql_query($sql, $con)) {
    print("Database fyi created.\n");
  } else {
    print("Database creation failed.\n");

If you run this script, you will get something like this:

Database fyi created.

2007-05-10, 4675👍, 0💬