简体   繁体   English

找不到表(SQLSTATE [HY000]:常规错误:1无此类表:用户)

[英]Can't find table (SQLSTATE[HY000]: General error: 1 no such table: users)

I'm trying to insert into a table, but it cannot find the table users. 我正在尝试插入表中,但是找不到表用户。 I get the error posted in the title. 我得到标题中张贴的错误。 The table most definitely exists: 该表绝对存在:

在此处输入图片说明

This is how I am connecting: 这就是我的连接方式:

 define("DB_DSN", "sqlite2:host=hosthere;dbname=dbnamehere");
 define("DB_USERNAME", " ");
 define("DB_PASSWORD", " ");

 $con = new PDO(DB_DSN, DB_USERNAME, DB_PASSWORD);
 $con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
 $sql = "INSERT INTO users(username, password) VALUES(:username, :password)";

I am using a free website host so I can't really edit much besides .htaccess. 我使用的是免费的网站托管服务商,因此除了.htaccess之外我无法进行其他任何编辑。 It has sqlite and sqlite2. 它有sqlite和sqlite2。 I tried with sqlite:host... but I still get same error. 我尝试使用sqlite:host ...,但仍然遇到相同的错误。 I'm still new to PDO and would appreciate any help. 我还是PDO的新手,希望能对您有所帮助。

Your connection string doesn't appear to be correct. 您的连接字符串似乎不正确。

There are no "host" and "dbname" variables for connecting to an SQLite database. 没有用于连接到SQLite数据库的“主机”和“ dbname”变量。 An SQLite database is a file, and all you need to open an SQLite database is the file path to this file. SQLite数据库是一个文件,打开SQLite数据库所需要做的就是该文件的文件路径。

The connection string is made up of the database type (sqlite2 in your case), followed by a colon (:) followed by the full path to your database. 连接字符串由数据库类型(在您的情况下为sqlite2),冒号(:)和数据库的完整路径组成。

So, for example, if your database is called "mydata.sqlite", and it's in the directory "/home/users/yayu/database", then your connection string would look like this: 因此,例如,如果您的数据库名为“ mydata.sqlite”,并且位于目录“ / home / users / yayu / database”中,则您的连接字符串将如下所示:

sqlite2:/home/users/yayu/database/mydata.sqlite

Thus, to use a constant as you supplied in your example, you would use the following: 因此,要使用示例中提供的常量,可以使用以下代码:

define("DB_DSN", "sqlite2:/home/users/yayu/database/mydata.sqlite")
$con = new PDO(DB_DSN)

That is all that's necessary to connect. 这就是连接所必需的。 Each SQLite database file has only one database (unless you explicitely attach another one). 每个SQLite数据库文件只有一个数据库(除非您显式附加另一个数据库)。 So there is no need to specify a database name. 因此,无需指定数据库名称。

For more information you can refer to the PHP online documentation of the SQLite PDO driver: http://us2.php.net/manual/en/ref.pdo-sqlite.php 有关更多信息,您可以参考SQLite PDO驱动程序的PHP在线文档: http : //us2.php.net/manual/en/ref.pdo-sqlite.php

I think the first thing I would do in your case is to find out where exactly your SQLite database file is located. 我认为针对您的情况,我要做的第一件事是找出SQLite数据库文件的确切位置。 It looks like you are using a web-based interface to manage your SQLite database. 您似乎正在使用基于Web的界面来管理SQLite数据库。 Try to see if there are some settings or similar options that show you the full path to the database. 尝试查看是否有一些设置或类似的选项向您显示数据库的完整路径。 If that doesn't help, contact the hosting provider and ask where the SQLite database file is located. 如果那没有帮助,请联系托管服务提供商并询问SQLite数据库文件的位置。

To ensure a table is in a specific database you can use MySQL SHOW TABLES to list tables. 为了确保表格在特定的数据库中,您可以使用MySQL SHOW TABLES列出表格。 Beware of leading spaces in names. 当心名称中的前导空格。

TRY 尝试

$con = new PDO(DB_DSN, DB_USERNAME, DB_PASSWORD);
$con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $db->query("SHOW TABLES FROM  yayu_zxq_users");
$tables = $stmt->fetchAll(PDO::FETCH_NUM);
print_r($tables);

暂无
暂无

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

相关问题 SQLSTATE[HY000]:一般错误:无法创建表 - SQLSTATE[HY000]: General error:Can't create table SQLSTATE [HY000]:一般错误:1005 无法创建表 - Laravel 4 - SQLSTATE[HY000]: General error: 1005 Can't create table - Laravel 4 SQLSTATE[HY000]:一般错误:1005 无法创建表 Laravel 8 - SQLSTATE[HY000]: General error: 1005 Can't create table Laravel 8 laravel “SQLSTATE [HY000]:一般错误:1 没有这样的表:用户”但存在“用户”表 - laravel "SQLSTATE[HY000]: General error: 1 no such table: user" but 'users' table exists 更新表格错误? (SQLSTATE [HY000]:一般错误) - Updating table error? (SQLSTATE[HY000]: General error) SQLSTATE[HY000]: General error: 1005 Can't create table `business`.`users` (errno: 150 "Foreign key constraint is incorrectly formed") Laravel 7 - SQLSTATE[HY000]: General error: 1005 Can't create table `business`.`users` (errno: 150 "Foreign key constraint is incorrectly formed") Laravel 7 Laravel 5.4:SQLSTATE[HY000]:一般错误:1005 无法创建表“外键约束格式不正确” - Laravel 5.4: SQLSTATE[HY000]: General error: 1005 Can't create table "Foreign key constraint is incorrectly formed" SQLSTATE[HY000]: 一般错误: 1005 Can't create table `school`.`posts` (errno: 150 "Foreign key constraint is wrongly forms") - SQLSTATE[HY000]: General error: 1005 Can't create table `school`.`posts` (errno: 150 "Foreign key constraint is incorrectly formed") PDOException:SQLSTATE[HY000]:一般错误:7890 找不到文件 - PDOException : SQLSTATE[HY000]: General error: 7890 Can't find file 需要帮助以查找错误SQLSTATE [HY000]:常规错误 - Need help to find error SQLSTATE[HY000]: General error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM