abstract:<?php //配置參數(shù); $dsn='mysql:host=127.0.0.1;dbname=luheng'; $username='root'; $password='root'; $pdo = new PDO($dsn,$username,$password); //檢測數(shù)據(jù)庫是否連接; try{ $pdo
<?php //配置參數(shù); $dsn='mysql:host=127.0.0.1;dbname=luheng'; $username='root'; $password='root'; $pdo = new PDO($dsn,$username,$password); //檢測數(shù)據(jù)庫是否連接; try{ $pdo; }catch(PDOException $e){ print_r($e->grtMessige()); exit; } // var_dump($pdo); // 綁定參數(shù)值修改數(shù)據(jù); //創(chuàng)建sql語句; // $sql = 'INSERT INTO `demo` SET name = :name, age = :age,sex=:sex '; 添加數(shù)據(jù); // $sql='delete from demo where id=:id'; 刪除數(shù)據(jù); // $sql='update demo set name=:name,age=:age where id=:id'; // //在數(shù)據(jù)庫中進(jìn)行預(yù)處理; // $a=$pdo->prepare($sql); // //傳參; // $name='老魯'; // $age=26; // $id=45; // // 參數(shù)綁定 // $a->bindParam('name', $name,PDO::PARAM_STR); // $a->bindParam('age', $age,PDO::PARAM_INT); // $a->bindParam('id', $id,PDO::PARAM_INT); // //進(jìn)行結(jié)果處理; // $resurt=$a->execute(); // //判斷結(jié)果是否處理成功; // if($resurt){ // echo "修改成功"; // }else{ // echo "修改失敗"; // die; // } // //關(guān)閉連接 // $pdo=null;
Correcting teacher:天蓬老師Correction time:2019-04-20 13:27:18
Teacher's summary:你這是一個(gè)完整的案例吧, 如果只需要連接部分, 不如把下面刪除掉