简体   繁体   English

PHP Mysqli查询不断返回false

[英]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). 我正在尝试在PHP中使用mysqli接口创建数据库表,但是查询调用始终返回false,并且数据库仍然为空(无表)。 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. 您的查询存在语法错误,因此返回为false。

You had missed to add the varchar size of the hash column. 您错过了添加哈希列的varchar大小的操作。

corrected query 更正的查询

$connection->query('CREATE TABLE IF NOT EXISTS users (
    name VARCHAR(20) NOT NULL,
    hash VARCHAR(255) NOT NULL
)');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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