1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| try{ $db = new PDO($settings['type'].":host=".$settings['host'].";dbname=".$settings['dbname'],$settings['user'],$settings['pass']); echo '连接成功'; }catch (PDOException $e){ die('error:'.$e->getMessage()); } echo '<hr />'; $sql = "INSERT INTO user(account,password,add_time,nickname) VALUES ('aaa','bbb',111,'ddd')"; $tem = $db -> prepare($sql); print_r($tem -> execute());
$sql = "INSERT INTO user(account,password,add_time,nickname) VALUES (:account,:password,:add_time,:nickname)"; $tem = $db->prepare($sql); $tem-> execute([ 'accounta' => 'ccc', 'password' => '555', 'add_time' => '111', 'nickname' => '666' ]);
|