简体   繁体   中英

PHP Mysqli query constantly returns false

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
)');

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
)');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM