Categories
PHP

How To Create Database In MySql Using PHP

How To Create Database In MySql Using PHP

In this tutorial i will teach you How To Create Database In MySql Using PHP.This tutorial will be very helpful when you are thinking of create a database through your PHP code.

CODE:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>How To Create Database In MySql Using PHP</title>
<style type="text/css">
body
{
margin:0px auto;
width:980px;
font-family:"Trebuchet MS", Arial, Helvetica, sans-serif;	
}
h2
{
font-size:30px;
text-align:center;	
}
.text
{
color:#090;
text-align:center;
font-size:20px;	
}
.hr
{
clear:both;	
margin-top:60px;
border-bottom:solid 2px rgba(0,0,0,0.4);
}
.footer
{
width: 100%;
text-align: center;
padding-top: 0px;
font-size: 16px;
}
</style>
</head>

<body>
<h2>How To Create Database In MySql Using PHP</h2>
<div class="text">
<?php
$connection= mysqli_connect("localhost","root","root");
if($connection){
echo "Connection Established";
}
else
{
echo "coonection fail";	
}


// Create database
$sql="CREATE DATABASE demo1";
if (mysqli_query($connection,$sql))
{
echo "<br><br><br>Database demo1 created successfully";
}
else
{
echo "<br><br><br>Error creating database: " . mysqli_error($connection);
}


?>
</div>

<!--hr-->
<br /><br /><br /><br />
<hr />

<!--footer-->
<div class="footer">
<p>© 2013 All rights reserved by HighTechnology.in
<a href="http://hightechnology.in" target="_blank">HighTechnology.in</a>
| Hosting Partner <a href="http://www.grootstech.com" target="_blank">Grootstech Solutions</a></p>
</div>
</body>
</html>