🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
[TOC] ## php5.6 pdo 适配文件 链接: https://pan.baidu.com/s/1mpJEXmWCixJ0OM9HV-UL9A 提取码: uij7 ## pdo ### 连接数据库 ``` $dsn = 'kdb:host=192.168.0.141;dbname=ANTDBMS;port=54321'; $user = 'SYSTEM'; $password = 'system'; $dbh = null; $dbh = new PDO($dsn, $user, $password, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));//错误时候抛出异常 ``` ### 添加 ``` try{ //预处理 $stmt = $dbh->prepare("INSERT INTO SYS_ADMIN (user_id, user_login, user_name,user_pwd) VALUES (?, ?, ?, ?)"); $id = 4; $fp = "123"; $stmt->bindParam(1, $id); $stmt->bindParam(2, $fp); $stmt->bindParam(3, $fp); $stmt->bindParam(4, $fp); $res = $stmt->execute(); var_dump($res); //不进行预处理 $dbh->exec("insert into sys_admin(user_id,user_login,user_name,user_pwd) values (6,'123','12321','123')"); }catch(Exception $e){ var_dump($e->getMessage()); } ``` ### 查看 ``` $PDOStatement = $dbh->query("select * from sys_admin",PDO::FETCH_ASSOC); foreach($PDOStatement as $v){ print_r($v); } ```