2

I am trying to create the database tables with the mysqli interface in PHP, however the query call always returns false and the database remains empty (no tables). I don't know what's wrong with this function, I also checked to make sure the database connection was successful and it was.

$connection->query('CREATE TABLE IF NOT EXISTS users (
name VARCHAR(20) NOT NULL,
hash VARCHAR NOT NULL
)');
Lilith
  • 437
  • 2
  • 11

1 Answers1

4

Your query has a syntax error and hence it is returning as false.

You had missed to add the varchar size of the hash column.

corrected query

$connection->query('CREATE TABLE IF NOT EXISTS users (
    name VARCHAR(20) NOT NULL,
    hash VARCHAR(255) NOT NULL
)');
RamC
  • 1,287
  • 1
  • 11
  • 15