<?php require 'pdo_config.php'; $dsn = "{$dbType}:host={$host};dbName={$dbName}}";// 创建数据源 try{ $pdo = new PDO ($dsn,$userName,$password); $sql = "update student set grade=80 where id=7"; $num = $pdo->exec($sql);//返回受影响的记录数量 if($num>0){ print '成功添加'; }else{ print '不成功'; } } catch(PDOexception $e){ die('操作失败'.$e->getMessage()); }