php 使用pdo对mysql数据库增删改查实例
1个回答
推荐于2016-08-30 · 知道合伙人软件行家
关注
展开全部
//连接、查询
try {
$dbh = new PDO('mysql:host=localhost;dbname=test', $user, $pass);
foreach($dbh->query('SELECT * from FOO') as $row) {
print_r($row);
}
$dbh = null;//释放资源
} catch (PDOException $e) {
print "错误!: " . $e->getMessage() . "<br></br>";
die();
}
//执行删除操作,插入、修改与此类似,更改SQL语句即可
$count = $dbh->exec("DELETE FROM fruit WHERE colour = 'red'");
try {
$dbh = new PDO('mysql:host=localhost;dbname=test', $user, $pass);
foreach($dbh->query('SELECT * from FOO') as $row) {
print_r($row);
}
$dbh = null;//释放资源
} catch (PDOException $e) {
print "错误!: " . $e->getMessage() . "<br></br>";
die();
}
//执行删除操作,插入、修改与此类似,更改SQL语句即可
$count = $dbh->exec("DELETE FROM fruit WHERE colour = 'red'");
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询