PHP/MySQL Problems (Engine Type, Autoincrement)

Discussion in 'PHP' started by kuepper, Feb 17, 2008.

  1. #1
    Hello,

    I'm having a problem implementing a script that creates database tables. I can create basic tables, but I need to define the specific engine type and autoincrement numbers.

    For example:
    ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 AUTO_INCREMENT=2

    Normally, when I run an SQL script, I'd just add the above after the close of the table creation ")". However, when I put this into a php script and attempt to execute it, it won't let me.

    My question is: Are there specific PHP commands that I need to use in order to execute those table modifications? Or, should I just be able to put the above on the end and it should run? (ie. the problem is elsewhere).

    Thanks in advance for any help! I'd greatly appreciate it!!!
     
    kuepper, Feb 17, 2008 IP
  2. daman371

    daman371 Peon

    Messages:
    121
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Yes. You put the query in the mysql_query function. You have to be connected to mysql through php and have the database selected though.

    
    mysql_connect(HOST, USERNAME, PASSWORD) or die(mysql_error());
    mysql_select_db(DBNAME) or die(mysql_error());
    mysql_query("CREATE TABLE test (id INT NOT NULL AUTO_INCREMENT PRIMARY KEY); ENGINE=MYISAM; AUTO_INCREMENT=2; DEFAULT CHARSET=utf8;") or die(mysql_error());
    
    PHP:
     
    daman371, Feb 18, 2008 IP