PHP Freelancer

Freelance PHP Developer

Mysql Tutorial – create or drop database

Posted on | March 8, 2009 | 4 Comments

Hello Friends,

If you are a learner (new) in PHP / Mysql and don’t know how to create mysql database or drop mysql database from php file than Here is the easiest and error-free way to create mysql database or drop mysql database with Mysql.

<?php
///*** This file will help you to create or drop database in MYSQL using PHP – Rakshit Patel **////

include(“mysql-connection.php”);

//** Creating database **//

$sql = “CREATE DATABASE testing”;
$res = mysql_query($sql);

//** Drop database **//

$sql = “DROP DATABASE testing”;
$res = mysql_query($sql);

////////////// OR /////////////////

//** Creating database **//

$sql = mysql_create_db(‘testing’);

//** Drop database **//

$sql = mysql_drop_db(‘testing’);

////////////////////////////////////

include(“mysql-connection-close.php”);
?>

Here first i have added mysql-connection.php file which will make connection with Mysql database. If you dont know how to make connection with Mysql database than click here.

Now You can create database by excuting query as per above or by just calling inbuilt function  mysql_create_db(“databasename”).

For droping database, you have 2 ways to do the task . one is by executing query as per above and the other by calling inbuilt function  mysql_drop_db(“databasename”).

At last i have included mysql-connection-close.php file.

<?php 
///*** This file will close MYSQL connection using PHP – Rakshit Patel **//// 

mysql_close($connection); // close mysql connection
?>

This is nothing but it will close connection which we have made earlier. Its not necessary but a sign of Good Programmer.

Cheers !!

      
Plugin by: PHP Freelancer

Comments

4 Responses to “Mysql Tutorial – create or drop database”

  1. Mysql database backup from PHP file | Online Hungama
    March 10th, 2009 @ 1:57 am

    [...] Now i have selected Mysql database (named testing ). if you have not created database than click here. [...]

  2. abcphp.com
    March 5th, 2010 @ 7:51 am

    Mysql Tutorial – create or drop database | Online Hungama…

    All about how to make create / drop database with mysql using PHP. If you are a new / Begineer in PHP/Mysql than just go through this article….

  3. Mysql Tutorial - Update / edit / modify data in to table | Online Hungama
    March 10th, 2010 @ 4:38 am

    [...] Now i have selected Mysql database (named testing ). if you have not created database than click here. [...]

  4. Mysql Tutorial - Select/Retrieve data from table | Online Hungama
    March 10th, 2010 @ 4:39 am

    [...] Now i have selected Mysql database (named testing ). if you have not created database than click here. [...]

Leave a Reply





Freelance PHP Developer