How can we create a database using PHP and MySQL?

Marc0

Well-known member
Registered
Joined
Jun 6, 2012
Messages
890
Points
28
Hi All


I am :confused: How can we create a database using PHP and MySQL?

Only expert ...

Thanks
 

HostPace

Active member
Registered
Joined
Apr 15, 2016
Messages
65
Points
8
If you're having a cPanel. You can easily create a Database in PHP using MySQL/phpMyAdmin from the panel.
 

harrygreen90

Active member
Joined
Dec 17, 2013
Messages
71
Points
8
If you're having a cPanel. You can easily create a Database in PHP using MySQL/phpMyAdmin from the panel.
Maybe the OP asked about how create a database using PHP and MySQL, not create a database in cPanel

Hi All


I am :confused: How can we create a database using PHP and MySQL?

Only expert ...

Thanks
I do a research and here's codes you can use to create a database using php.

Code:
<?php
   $dbhost = 'localhost:3036';
   $dbuser = 'root';
   $dbpass = 'rootpassword';
   $conn = mysql_connect($dbhost, $dbuser, $dbpass);
   
   if(! $conn ) {
      die('Could not connect: ' . mysql_error());
   }
   
   echo 'Connected successfully';
   
   $sql = 'CREATE Database test_db';
   $retval = mysql_query( $sql, $conn );
   
   if(! $retval ) {
      die('Could not create database: ' . mysql_error());
   }
   
   echo "Database test_db created successfully\n";
   mysql_close($conn);
?>
Hope it helps!
 

machinedock

New member
Registered
Joined
Aug 18, 2016
Messages
5
Points
0
mysql is outdated and not recomment to create database, you can use PDO or mysqli instead of mysql.
The codes for mysqli is
PHP:
<?php
$link=mysqli_connect("localhost","Username","password","dbname");
if(!$link)
{
     die('Could not connect: ' . mysqli_error($link));
}
else
{
if(myqli_query($link,"CREATE DATABASE database_name"))
{
echo "Success";
}
mysqli_close($link);
}

?>
 
Older Threads
Replies
18
Views
7,183
Replies
5
Views
3,714
Newer Threads
Replies
0
Views
2,296
Replies
1
Views
2,681
Latest Threads
Replies
0
Views
35
Replies
1
Views
40
Replies
0
Views
235
Replies
1
Views
52
Recommended Threads
Replies
2
Views
2,633
Replies
3
Views
3,157
Replies
0
Views
2,899
Replies
13
Views
2,623
Replies
1
Views
2,689

Latest Hosting OffersNew Reviews

Sponsors

Tag Cloud

You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an alternative browser.

Top