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
)');
2
  • 3
    This is where showing mysqli errors is very helpful. Commented Dec 17, 2017 at 18:11
  • 3
    You need to define a size/length for the hash varchar Commented Dec 17, 2017 at 18:12

1 Answer 1

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
)');
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.