php - Uncaught Error : Undefined class constant 'ERRMODE_EXPECTION'

标签 php mysql pdo

我正在尝试构建一个注册系统并将用户名和密码存储在数据库中

我用 PHP 编写了代码,但我在 PDO 中遇到错误,并且找不到解决方案 错误:

Uncaught Error: Undefined class constant 'ERRMODE_EXPECTION' in /storage/ssd4/295/11285295/public_html/config.php:8 Stack trace: #0 /storage/ssd4/295/11285295/public_html/index.php(2): require_once() #1 {main} thrown in /storage/ssd4/295/11285295/public_html/config.php on line 8

我的代码:

<?php
$db_user = "id11285295_useraccounts";
$db_password = "(my password here)";
$db_name = "id11285295_useraccounts";


$db = new PDO('mysql:host=localhost;db_name=' . $db_name . ';charset=utf8',  $db_user, $db_password);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXPECTION);

此外,我还有另一个注册页面需要此功能

最佳答案

第一个错误行表示问题出在指定的字符集上。 utf8-unicode-ci是字符集utf8下的排序规则,而不是字符集。

参见documentation关于字符集。

关于php - Uncaught Error : Undefined class constant 'ERRMODE_EXPECTION' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58474611/

相关文章:

php:强制下载到高清?

php - 是否可以使用 Javascript 读取 PHP session ?

mysql - 构造mysql大表

php - MySQL 事务与锁

php - SQLSTATE[HY000] [2002] 没有这样的文件或目录 - PHP 守护进程

mysql - PDO 更新 - 保持原始值

php - 如何在PHP中对数组和数据进行排序?

php - 在 Apigility 中使用 "DB Connect"生成新服务时出错

MySQL——分层选择

php - 数据库:通过查询和字段格式化直接在数据库中生成唯一的字符串