Monday, January 16, 2012

Creating Database in Php and Mysql

Sample code for Creating mysql database in php :
<?php
$db="mydb";
$information="information";
$login="login";
$link=mysql_connect("localhost","root") or die("could not connect");
if(!mysql_query('CREATE DATABASE if not exists '.$db, $link)) echo "Error Creating DataBase!";
else
        print "Database Create";

?>

Sample code for Creating table in mysql database with php :
<?php
$db="mydb";
$information="information";
$login="login";
$link=mysql_connect("localhost","root") or die("could not connect");
mysql_select_db($db) or die("Database doesn't Exist");
        $sql="CREATE TABLE if not exists $login (
        `Index` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
            `name`       VARCHAR( 200 ) ,
            `username`  VARCHAR( 200 )  ,
            `password`        VARCHAR( 200 ),
            `repassword`  VARCHAR( 200 )
                   
               ) ENGINE = MYISAM ";
        mysql_query($sql,$link) or die("Table Creating Error");
?> 

No comments:

Post a Comment