<?php
header("Content-type: text/html; charset=utf-8");
$dbms='mysql';
$dbName='goodsdb';
$user='root';
$pwd='root';
$host='localhost';
$charset = 'utf8';
$dsn="$dbms:host=$host;dbname=$dbName;charset=$charset";
try{
$pdo=new PDO($dsn,$user,$pwd);
}
catch(Exception $e)
{
echo $e->getMessage();
}
//查询
$sql = "select * from stu where name=? limit 1";
//准备sql模板
$stmt = $pdo->prepare($sql);
$name = 'a';
//绑定参数
$stmt->bindValue(1,$name);
//执行预处理语句
$stmt->execute();
//推荐这种方式来获取查询结果
while ($row=$stmt->fetch())
{
print_r($row);
}
//释放查询结果
$stmt = null;
//关闭连接
$pdo = null;
php操作pdo实现查询
最新推荐文章于 2023-12-19 20:05:58 发布