表不存在。检查表名是否正确。
你的PHP应用在使用PDO连接MySQL时遇到了表不存在的问题:
'pdo_code' => '42S02',
'db_code' => 1146,
'db_error' => 'Table \'database_name.table_name\' doesn\'t exist'
function tableExists($pdo, $tableName, $database = null) {
try {
$database = $database ?: $pdo->query('SELECT DATABASE()')->fetchColumn();
$stmt = $pdo->prepare("SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = ? AND table_name = ?");
$stmt->execute([$database, $tableName]);
return $stmt->fetchColumn() > 0;
} catch (PDOException $e) {
return false;
}
}
$tableName = 'users';
if (!tableExists($pdo, $tableName)) {
echo "表 {$tableName} 不存在,正在创建...";
} else {
$stmt = $pdo->prepare("SELECT * FROM {$tableName}");
$stmt->execute();
}