0

I am messing around with OOP mysqli. And I stumbled upon this problem:

There was an error running the query [You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'CREATE TABLE IF NOT EXISTS engine.users ( ID INT(11) NOT NULL, USERNAME ' at line 1]

This is the PHP code:

    function InstallDB($db){
    $sql = 
    "CREATE DATABASE IF NOT EXISTS `$this->dbname`; ".
    "CREATE TABLE IF NOT EXISTS `$this->dbname`.`$this->users` ( ".
    "`ID` INT(11) NOT NULL, ".
    "`USERNAME` varchar(60) NOT NULL,".
    "`PASSWORD` varchar(60) NOT NULL,".
    "`EMAIL` varchar(100) NOT NULL,".
    "`IMAGE` varchar(250) NULL,".
    "`LEVEL` INT(11) NOT NULL DEFAULT '1'".
    ") ENGINE=InnoDB  DEFAULT CHARSET=utf8;".

    "CREATE TABLE IF NOT EXISTS `$this->dbname`.`$this->settings` (".
    "`DOMAIN` varchar(60) NOT NULL,".
    "`SLOGAN` varchar(255) NOT NULL,".
    "`EMAIL` varchar(100) NOT NULL".
    ") ENGINE=InnoDB  DEFAULT CHARSET=utf8;";

    if(!$result = $db->query($sql)){
        die('SQL['.$sql.']<br>There was an error running the query [' . $db->error . ']<br>');
    }

    echo "Installed!<br>";
}

Tried different quote marks, no luck. I also echoed the $sql, copied it and executed in phpmyadmin, it worked perfectly. But still it won't do anything inside of PHP. Thanks.

Morsus
  • 107
  • 1
  • 16

1 Answers1

1

Use multi_query instead query, because you would like to multiple query not only one. As you can see the issue appeared right away after first query.

http://php.net/manual/en/mysqli.multi-query.php

Peter
  • 748
  • 6
  • 20