mysql db creation

Discussion in 'PHP' started by divinequran, Dec 20, 2008.

  1. divinequran

    divinequran New Member

    Joined:
    Oct 9, 2008
    Messages:
    62
    Likes Received:
    1
    Trophy Points:
    0
    Occupation:
    Software Engineer
    Home Page:
    http://divinequran.com/
    Hi,

    Is there is any option to create mysql data base automatically without using cpanel to create database, I use the following code but it does not create's Db on website.
    mysql_query("CREATE DATABASE fig",$connection);

    It creates DB in local but not in website?
     
  2. XenZy

    XenZy New Member

    Joined:
    Dec 30, 2008
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    0
    I would recommend manually creation of databases. Then controlling them through php, and make sure the connection is right. You can use this script to connect to your database ( it is very simple but works )

    PHP:
    <?php
    $database
    ['host'] = 'host'// change to your host
    $database['username'] = 'username'// change to username
    $database['password'] = 'password'// change to password
    $database['name'] = 'database'// change to database name

    $db mysql_connect($database['host'], $database['username'], $database['password']) OR die ('Cant connect to the database');
    mysql_select_db($database['name'], $db); // connection of database shouldn't be touched.
    ?>
     
  3. openwave

    openwave New Member

    Joined:
    Dec 30, 2008
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Home Page:
    http://www.openwavecomp.com/
    simple db creation is


    mysql_connect("localhost","root","");
    mysql_select_db("databasename");
    mysql_query("select * from tablename");
     
  4. XenZy

    XenZy New Member

    Joined:
    Dec 30, 2008
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    0
    Huh? thats not how you create a database, its pretty much what i posted but way simpler and no connecting? That is how you select a database. Well not even, since you missed out some code.
     
  5. divinequran

    divinequran New Member

    Joined:
    Oct 9, 2008
    Messages:
    62
    Likes Received:
    1
    Trophy Points:
    0
    Occupation:
    Software Engineer
    Home Page:
    http://divinequran.com/
    Yes, iam able to connect to database and do manipulation after creation database on my site, i want to know is there is any option to create db using code without using cpanel
     
  6. XenZy

    XenZy New Member

    Joined:
    Dec 30, 2008
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    0
    PHP:
    <?php
    $db 
    mysql_connect("host","user","pass");
    if (!
    $db)
      {
      die(
    'Could not connect: ' mysql_error());
      }     if (
    mysql_query("CREATE DATABASE my_db",$db))
      {
      echo 
    "Database created";
      }
    else
      {
      echo 
    "Error creating database: " mysql_error();
      }     
    mysql_close($db);
    ?>
    That's to create a database.
     
  7. divinequran

    divinequran New Member

    Joined:
    Oct 9, 2008
    Messages:
    62
    Likes Received:
    1
    Trophy Points:
    0
    Occupation:
    Software Engineer
    Home Page:
    http://divinequran.com/
    Finally my hosting company said database have to be created manually and they wont authorize to create DB using code. Thanks for your reply
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice