前两天了解了一下PDO连接数据库的相关资料,配置相关在网路上都有很多相关资料,我在这里说说解决中文乱码显示问题
我的环境是appsver包,
在网上最常出现的解决中文乱码显示的代码是:
第一种:PDO::__construct($dsn, $user, $pass, array
(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES'utf8';"));
我试过用第一种方法,可结果是,name字段只显示一个‘C'字符。之后的本该显示中文的地方却是空白。
结果是这样的:如图1示
第二种:PDO::__construct($dsn, $user, $pass);
PDO::exec("SET NAMES 'utf8';");
第二种我也在我的环境里测试过,显示效果如图1所示,碰到这种情况,香港虚拟主机,把utf8替换成GBK,就能显
示了。另外,这里的PDO::在使用的时候用$pdo->代替,当然,这个是个变量,变量名称可以自己定义。
第三种:$pdo->query('set names utf8;');
至于第三种呢,看了上面两种,应该也知道要吧utf8替换成GBK,也能正确显示了。
这几种我都测试过了。都行。哈哈。另外,我在这里还介绍一种解决中文乱码的一种方法,不过大同小异,
基本和第三种没什么却别,香港服务器,不通的是,这种方法,没用query而是用exec,代码如下:
$pdo->exec("SET CHARACTER SET GBK");
呵呵。怎么样啊,这四种方法我都亲自试过了。 ,香港空间

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Chinese version
Chinese version, very easy to use

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 Mac version
God-level code editing software (SublimeText3)