* PDO connection data
* 1. PDO is the middle layer, or abstraction layer, between PHP and other databases
* 2. PDO shields the differences between databases. Provides a unified access interface to PHP
* 3. The first step in using PDO is to generate a PDO object. All functions must be called using this object
* 4. Success Return PDO object, failure throws exception
//1. Configuration parameters
* DNS: Data source
* Basic format: Database type: attribute 1: value 1; Attribute 2: Value 2;...
* Type: such as mysqli, oracle, etc.
* Attribute: host, default database, default character set, default port number
* For example: mysql:host=127.0.0.1;dbname=php;charset=utf8;port=3306;
$dsn = 'mysql:host=localhost; dbname=php; charset=utf8; port=3306';
//Database user name
$userName = 'root';
//Database user password
$password = 'root';
//Configure connection properties
$options = [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, //设置错误模式
PDO::ATTR_CASE => PDO::CASE_NATURAL, //数据表字段保持不变
PDO::ATTR_EMULATE_PREPARES => true, //启用PDO模拟
PDO::ATTR_PERSISTENT => true, //启用持久性连接
];//Use try-catch() to catch possible errors
try {
//调用PDO构造函数实例化PDO类,创建PDO对象
$pdo = new PDO($dsn, $userName, $password, $options);
//连接是所有操作的基础,无论你设置的错误模式级别是什么,都会强制使用EXCEPTION异常模式
} catch (PDOException $e) {
print 'Connect ERROR!:'.$e->getMessage(); //推荐使用英文提示,以防止页面中文乱码
die(); //连接错误是致命错误,必须停止脚本的执行
}//Disconnect PDO connection
$pdo = null;
//Destroy the PDO object
unset($pdo);
//More often, you can use the abbreviation:
$pdo = new PDO('mysql:dbname=php;','root', 'root'); //其它参数取默认值

Hot AI Tools

Undress AI Tool
Undress images for free

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

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

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

WebStorm Mac version
Useful JavaScript development tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

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

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment






