<?php
$pdo
=
new
PDO(
'mysql:host=127.0.0.1;dbname=php_io'
,
'root'
,
'root'
);
$sql
= "INSERT IGNORE INTO `user`(`name`,`sex`,`age`,`email`,`password`,`status`,`create_time`)
VALUES (:user_name,:sex,:age,:email,:password,:status,:create_time)";
$stmt
=
$pdo
->prepare(
$sql
);
$name
=
'宋江'
;
$sex
=
'0'
;
$age
=
'58'
;
$email
=
'zong@php.cn'
;
$password
= sha1(
'aaad'
);
$status
=
'1'
;
$create_time
= time();
$stmt
->bindParam(
':user_name'
,
$name
,
$pdo
::PARAM_STR,100);
$stmt
->bindParam(
':sex'
,
$sex
,
$pdo
::PARAM_INT,2);
$stmt
->bindParam(
':age'
,
$age
,
$pdo
::PARAM_INT);
$stmt
->bindParam(
':email'
,
$email
,
$pdo
::PARAM_STR,200);
$stmt
->bindParam(
':password'
,
$password
,
$pdo
::PARAM_STR,40);
$stmt
->bindParam(
':status'
,
$status
,
$pdo
::PARAM_INT);
$stmt
->bindParam(
':create_time'
,
$create_time
,
$pdo
::PARAM_INT);
if
(
$stmt
->execute()){
echo
(
$stmt
->rowCount()>0) ?
'成功添加了 '
.
$stmt
->rowCount().
' 条记录'
:
'没有记录被添加'
;
}
else
{
exit
(print_r(
$stmt
->errorInfo(),true));
}