mysql php pdo例_PHP的PDO操作实例

try{

$dbms='mysql';          //数据库类型 ,对于开发者来说,使用不同的数据库,只要改这个,不用记住那么多的函数

$host='127.0.0.1';      //数据库主机名

$dbName='books';      //使用的数据库

$user='root';           //数据库连接用户名

$pass='';              //对应的密码

$dsn="$dbms:host=$host;dbname=$dbName";

$pdo = new PDO($dsn, $user, $pass);  //初始化一个PDO对象,就是创建了数据库连接对象$pdo

*/

//echo $_POST['bookname'];

//插入出数据库语句,图片数据前要加上0x,用于表示16进制数

//$query = "insert into book(name,createtime,price,author,publish) value('$bookname','$booktime','$bookprice','$bookauthor','$bookpublish')";

//$query = "insert into images(pic) values('".$name."','".$type."',0x".$imgdata.")")

//$query = "insert into book(name,createtime,price,author,publish,pic) values(':name',':createtime',':price',':author',':publish',0x".$imgdata.")";

//$query = "insert into book(name,createtime,price,author,publish,pic) values(?,?,?,?,?,0x".$imgdata.")";

//$result=$pdo->prepare($query);   //准备查询语句

//$result=$pdo->prepare("insert into book(name,createtime,price,author,publish,pic) values(?,?,?,?,?,0x".$imgdata.")");   //准备查询语句

//$result=$pdo->prepare("insert into book(name,createtime,price,author,publish,pic) values(?,?,?,?,?,0x.?)");

//$result=$pdo->prepare("insert into book(name,createtime,price,author,publish) values(?,?,?,?,?)");

//echo $_POST['imagedata'];

$result=$pdo->prepare("insert into book(name,createtime,price,author,publish,pic) values(?,?,?,?,?,?)");

//echo $_POST['bookname'];

/*

$result->bindValue(1,$_POST['bookname']);

$result->bindValue(2,$_POST['booktime']);

$result->bindValue(3,$_POST['bookprice']);

$result->bindValue(4,$_POST['bookauthor']);

$result->bindValue(5,$_POST['bookpublish']);

$result->bindValue(6,$_POST['imagedata']);

*/

// echo "

".time()."

"

// echo $_POST['imagedata'];

/*

$result->bindParam(':name', $_POST['bookname']);

$result->bindParam(':createtime',$_POST['booktime']);

$result->bindParam(':price', $_POST['bookprice']);

$result->bindParam(':author',$_POST['bookauthor']);

$result->bindParam(':publish',$_POST['bookpublish']);

*/

/*

if($result->execute() > 0)

{

echo "
insert pic success\n";

echo "

insert success! !!!!!!!!!!!!!!qq
";

}

else

{

echo "

insert failed 26".mysql_error()."
";

}

}

catch(PDOException $e)

{

die("Error:".$e->getMessage()."
");

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值