Breaking

LightBlog

Saturday 4 July 2015

How to Create MySQL Database in PHP


Create a Database: If You can store the information in PHP Then You can use the database. Database is collection of Table. And Table is collection of row and column which can information is store. To create and delete a database you should have admin privilege. It is very easy to create a database in PHP. You can also use SQL Query to create a database.
Syntax
Create database database-name;
Create database customer;
                                                       
How to Create MySQL Database in PHP

Selecting the Database : Once you establish a connection with database server then it is required to select a particular database where you create all table. This is require because there may be multiple databases reside on a single server and you can do work with single database at a time. PHP provide a function mysql_select_db to select the database.
Syntax
mysql_select_db (dbname, connection);

They can use the two parameter such as .
  • db_name – use the database name.
  • connection – (optional) if not specified then last opened connection by mysql_connect will be used.
Example

<?php
$con=mysql_connect(“localhost”, “deep “, 12345);
if (!$con)
{
die(“could not be connect the database” . mysql_error());
}
echo “ connected successfully “;
mysql_select_db (‘test_db’);
mysql_close ($con);
?>

 
Adbox