FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


How do you Create a New Database using a php script?





Possum
Hi

I can create a new Database using the MySQL console and phpMyAdmin.

But How can I create a new database using a php script?

Thank You
Fire Boar
Just run the query CREATE DATABASE databasename after calling mysql_connect with appropriate privileges. That should do the trick.
Flakky
Note that PhpMyAdmin often returns code to recreate the action you have done in PhpMyAdmin but then in php. Smile
Possum
My apologies. I should have Googled my question first.

Code:
<?php     /***  mysql-create_db.php  ***/
  $user      = "root";
  $userpass  = "password";
  $newdbname = "database_name";
  $con = mysql_connect("localhost", $user, $userpass)
                 or die("Connection failure <br/>". mysql_error() );
  mysql_query("CREATE DATABASE $newdbname")
    or die("creating database fails... <br />". mysql_error() );
    mysql_close($con);
?>
Flakky
Luckily Google is the answer to everything Wink
Possum
The force it Strong with Google
Related topics
[tutor] How to protect images without htaccess using PHP
Phoenix free PHP scripts
Inserting data to MYSQL with a PHP script
How to update database?
php script help!
array check box on php script using $_POST
PHP script to create email addresses/ftp accounts/etc...
Can't create a new database [resolved]
php script for Changing file permissions & owner
Uploading an Image using PHP script - RESOLVED
Using PHP code from a Database
"Drop Down List Box" Using PHP and MySql
create new database privilege
What to learn first?
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.