Help needed with PHP Script: To Install Tables into a MySql Database

Discussion in 'Programming' started by kingc, Aug 30, 2008.

  1. #1
    ok ... So here's what I'm trying to do.

    I am selling a site that I want people to be able to easily install the database and tables for it to use; here's what I have so far; but it's not working

    <?php require_once('../Connections/sitewidecms.php'); ?>
    <?php
    
    
    // Table structure for table `bannersdb`
    
    
    $sql = 'CREATE TABLE `sitewide`.`bannersdb` (
      `banner_id` int(100) NOT NULL auto_increment,
      `banner_name` varchar(500) NOT NULL,
      `banner_href` varchar(500) NOT NULL,
      `banner_alt` varchar(200) default NULL,
      PRIMARY KEY  (`banner_id`)
    ) ENGINE=MyISAM AUTO_INCREMENT=0 DEFAULT CHARSET=utf8 AUTO_INCREMENT=0' ;
     echo 'Creating table: \'bannersdb\'....';
    
    ?>
     
    PHP:
    I cut the code short, because basically If I can figure out how to use this script to create ONE table, I can use it to create the other tables as well; The 'required' file is a simple file that includes information on how to connect to the database.

    <?php
    # FileName="Connection_php_mysql.htm"
    # Type="MYSQL"
    # HTTP="true"
    $hostname_sitewidecms = "localhost";
    $database_sitewidecms = "sitewidecms";
    $username_sitewidecms = "username";
    $password_sitewidecms = "password";
    $sitewidecms = mysql_pconnect($hostname_sitewidecms, $username_sitewidecms, $password_sitewidecms) or trigger_error(mysql_error(),E_USER_ERROR); 
    ?>
    PHP:
    So my question is, what am I missing to make this script work to install what I need; so that I can include a decent 'install' script to help people get up and running with ease.

    thanks
     
    kingc, Aug 30, 2008 IP
  2. dumsky

    dumsky Peon

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    What is the error message you get?
     
    dumsky, Aug 31, 2008 IP
  3. vasago

    vasago Peon

    Messages:
    95
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #3
    You have to add below:
    mysql_query($sql);

    your statement "$sql = '.....'" is just assigning the sql query text to a variable. It is ok, but you need to actually execute it afterwords with mysql_query command.

    good luck.
     
    vasago, Sep 1, 2008 IP
  4. kingc

    kingc Member

    Messages:
    16
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    36
    #4
    Ohh... I see - because right now, Nothing happens at all.

    That makes sense now; Forgive me I'm still a novice with php - still learning - I'll give this a try and see what happens. Thanks
     
    kingc, Sep 8, 2008 IP
  5. Masterful

    Masterful Well-Known Member

    Messages:
    1,653
    Likes Received:
    28
    Best Answers:
    0
    Trophy Points:
    140
    #5
    I'm afraid that is out of the question! You will NEVER be forgiven. EVER! :mad:

    Just kidding, dude. :) No need to ask for forgiveness. I suppose you're just being polite.
     
    Masterful, Sep 8, 2008 IP
  6. ausome

    ausome Peon

    Messages:
    97
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    You'll need this as well to connect to the DB.
    I didn't see it in your code and you've probably worked this out already but here goes...

    $db_selected = mysql_select_db($database_sitewidecms,$sitewidecms);
    PHP:
    And in a way we are all still Novices at this stuff.
    The Major thing is - you are giving it a go and asking questions.
    Keep at it!

    Cheers
    Tim
     
    ausome, Sep 15, 2008 IP