Correction status:Uncorrected
Teacher's comments:
//数据库连接参数$db = [ 'type' => 'mysql', 'host' => 'localhost', 'dbname' => 'ouyangke', 'username' => 'root', 'password' => 'root'];
$dsn = $db['type'] . ':host=' . $db['host'] . ';dbname=' . $db['dbname'];
try { $pdo = new PDO($dsn, $db['username'], $db['password']);// print_r($pdo);} catch (PDOException $e) { die('错误提示:'.$e->getMessage());};
$stmt = $pdo->prepare($sql);
$name = 'els';$alias = '俄罗斯动画片';$stmt->bindParam('name', $name, PDO::PARAM_STR);$stmt->bindParam('alias', $alias, PDO::PARAM_STR);
//PDOStatement类,对增删改查进行操作$add = $stmt->execute();print_r($add);if ($add){ $count=$stmt->rowCount(); if ($count>0){ echo '数据插入成功'; }else{ echo '数据插入失败'; }}else{ die(print_r($stmt->errorInfo(),true));}
//unset($pdo);//print_r($pdo);$pdo=null;print_r($pdo);