ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
**一.创建sqlite3数据库php8.db** ``` sqlite3 /sqlite3/php8.db ```   **二.sql基础操作** 1.创建表user ``` create table user(id integer PRIMARY KEY AUTOINCREMENT,name text,age integer); ``` 2.插入数据 ``` insert into user values(1,'user1',20); insert into user values(2,'user2',22); ``` 3.查询数据 ``` select * from user; ```   **三.linux下查看数据库文件(十六进制)** ``` xxd php8.db ```   **四.php pdo操作sqlite3 php8数据库** ``` $pdo = new PDO('sqlite:/sqlite3/php8.db'); ```   **五.pdo报错类型PDO::ATTR_ERRMODE** ``` 1.PDO::ERRMODE_SILENT 0 2.PDO::ERRMODE_WARNING 1 3.PDO::ERRMODE_EXCEPTION 2 ```   **六.pdo设置错误类型** 1.设置 ``` $pdo->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_WARNING); ``` 2.获取 ``` $pdo->getAttribute(PDO::ATTR_ERRMODE); ```   **七.pdo操作user表** ``` $sql='select * from user2'; $smt=$pdo->prepare($sql); $smt->execute(); $arr=$smt->fetchAll(PDO::FETCH_ASSOC); ```   **八.pdo操作异常捕捉** ``` try{ $pdo=new PDO('sqlite:/sqlite3/php8.db'); $smt=$pdo->prepare('select * from user2'); $smt->execute(); $rows=$smt->fetchAll(PDO::FETCH_ASSOC); }catch(PDOException $e){ echo $e->getMessage(); } ```