码迷,mamicode.com
首页 > 数据库 > 详细

php连接数据库的几种方式

时间:2018-12-08 11:25:39      阅读:170      评论:0      收藏:0      [点我收藏+]

标签:sele   错误   bsp   fetch   err   and   exec   info   username   

 

<?php
$name = $_POST["u_name"]; //flag1:$_POST["u_name"]
$pass = $_POST["u_pass"];
$sql2 = "select * from admin where username = ? and password= ?";
$db = new PDO(‘mysql:host=127.0.0.1;dbname=login;charset=UTF-8‘, ‘root‘, ‘123456789‘);
//flag2:new PDO(‘mysql:host=127.0.0.1;dbname=login;charset=UTF-8‘,‘root‘, ‘123456789‘);
$sth = $db->prepare($sql2); //flag3:$db->prepare($sql2);
$sth->bindParam(1,$name,PDO::PARAM_STR,12);
//flag4:$sth->bindParam(1,$name,PDO::PARAM_STR,12);
$sth->bindParam(2,$pass,PDO::PARAM_STR,12);
$sth->execute();
$res = $sth->fetch();
//flag5:$res = $sth->fetch();
if (empty($res))
{
echo "错误!";
// print_r($sth->errorInfo());
}else{
echo "Success!!!!";
}

 

php连接数据库的几种方式

标签:sele   错误   bsp   fetch   err   and   exec   info   username   

原文地址:https://www.cnblogs.com/nul1/p/10086413.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!