<?php
$db = new mysqli(host, user, pass, dbname);
$query = "
create table stuff
( stuffid int not null auto_increment,
username varchar not null
)
";
$db->query($query); // There is an error near "stuffid int not null auto_increment"
?>
The “auto_increment” bug appears. How do I fix this?
No, case doesn’t matter. What does matter is that a primary key is defined on the table and how it is defined. In your first example, you didn’t specify a primary key at all. In the second one you specified it in a format that doesn’t work on MySQL. That’s not a “bug” in MySQL. You’re sending queries for a different database system to MySQL, of course that won’t work.
Just a suggestion, but maybe you can add the table in phpMyAdmin with their form interface? That way, phpMyAdmin can generate the correct SQL code for you (which you can view and backup if you want).
I am trying in an online IDE, and here is what I get:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘not null
)’ at line 3
As it says, check the manual that corresponds to your MySQL server version
Check out my code:
CREATE TABLE stuff (
id INT NOT NULL auto_increment,
name varchar(100) NOT NULL,
PRIMARY KEY (id)
) ENGINE=InnoDB;