SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict
    Join Date
    Nov 2009
    Posts
    312
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Creating a database

    Hi,

    I am building a CMS from scratch and my first step is the installation. I would like to create the database automatically on the install page (something like Fantastico) but I don't know how to do that.

    I know how to create a database using the following code, but that requires the db host, db username and db password information. Fantastico installs a script (such as WordPress) without bothering with that details. Do you have any ideas how to do that?

    PHP Code:
    <?php
    $con 
    mysql_connect("localhost","db_username","db_password");
    if (!
    $con)
      {
      die(
    'Could not connect: ' mysql_error());
      }

    if (
    mysql_query("CREATE DATABASE my_db",$con))
      {
      echo 
    "Database created";
      }
    else
      {
      echo 
    "Error creating database: " mysql_error();
      }

    mysql_close($con);
    ?>

  2. #2
    SitePoint Enthusiast
    Join Date
    Nov 2011
    Location
    Florida
    Posts
    58
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    you can run checks to see if the tables exist on the initial load and define a constant or variable to determine if it needs to run the tables installation or not, an older (imo better) technique is create an install file and delete it after the site is installed

    but those are just my opinions

  3. #3
    SitePoint Wizard bronze trophy Immerse's Avatar
    Join Date
    Mar 2006
    Location
    Netherlands
    Posts
    1,661
    Mentioned
    7 Post(s)
    Tagged
    1 Thread(s)
    Please note that it is often not possible to create databases on shared hosting - hosts don't give permission for this.

    Fantastico does it differently: it's a part of cPanel and already has access to your credentials.

  4. #4
    SitePoint Addict
    Join Date
    Nov 2009
    Posts
    312
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Immerse View Post
    Please note that it is often not possible to create databases on shared hosting - hosts don't give permission for this.

    Fantastico does it differently: it's a part of cPanel and already has access to your credentials.
    I see, that means I will omit the database creation and just get the database details on the install page. Thanks for the comment.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •