Home / PHP / Create database in mysql using php coding script

Create database in mysql using php coding script

Automatically generate db in MySQL phpmyadmin Programmatically through php coding.

Creating database using php scripting coding is very similar to manually create database using phpmyadmin xampp control panel but in manually method web developer need to open phpmyadmin and then create db itself but using php script all you have to do is set your localhost username, password and host into php scripting file then put your db name which you want to create using php script then run this file. So here is the complete step by step tutorial for how to Create database in mysql using php coding script.

[sociallocker id=”858″]

Download

 

[/sociallocker]

 

How to Create database in mysql using php coding script.

1. Copy scripting code form below.

<html>
<head> 
<title>Create database in mysql using php script</title>
</head> 
<body>

 <h2>Click on button to create MySQL database dynamically</h2>
<form method="post" action="">
<input type="submit" name="submit" Value="submit">
</form>
 
</body>
</html>

<?php
if (isset($_POST['submit']))
{

$Mysql_connect_link = mysql_connect('localhost', 'root', '');
if (!$Mysql_connect_link) {
 die('Could not connect: ' . mysql_error());
}
//Define your database name here.
$sql = "CREATE DATABASE TestDB";
if (mysql_query($sql, $Mysql_connect_link)) {
 echo "Database TestDB created successfully\n";
} else {
 echo 'Error creating database: ' . mysql_error() . "\n";
}
 
}

?>

Copy your file in XAMPP -> htdocs -> project_name_folder -> db.php

Start Xampp control panel then start Apache & MySQL .

Open your web browser the type localhost/sample_project/db.php .

Screenshots :

db_create_script

Click on Submit button to create database using php script on button click.

Create database in mysql using php coding script

Now open your PhpMyAdmin control panel and your your database will be created their successfully.

testdb

About VikasKumar

This Website is Full Free Download Metas ...................

Check Also

Use strlen function in php to get count string length

How to find string variable length in numbers in php using strlen() function. Strlen() function …