php_DBHelper
生活随笔
收集整理的這篇文章主要介紹了
php_DBHelper
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
php_DBHelper
包含【CURD】 demo
<?php class DBHelper{ private $host="localhost"; private $userName="root"; private $pwd="root"; private $DBName="mytest"; /*** 獲取數(shù)據(jù)*/ function GetQuery($sql){$conn=new mysqli($this->host,$this->userName,$this->pwd,$this->DBName);if(!$conn){echo "conn mysql error";mysqli_close($conn);return;}mysqli_query($conn,"set names utf8");$return=mysqli_query($conn,$sql);mysqli_close($conn);return $return; } /*** 增刪修函數(shù)*/ function NOQuery($sql){$conn=new mysqli($this->host,$this->userName,$this->pwd,$this->DBName);if(!$conn){echo "conn mysql error";mysqli_close($conn);return;}mysqli_query($conn,"set names utf8");mysqli_query($conn,$sql);//獲取操作行數(shù)$rows=mysqli_affected_rows($conn);mysqli_close($conn);return $rows;//別忘記$符號 }} #開始執(zhí)行測試 $db=new DBHelper(); #添加數(shù)據(jù) // $db->NOQuery("insert into users values(0,'damo','11','易筋經(jīng)')"); #修改數(shù)據(jù) // $db->NOQuery("update users set userName='達(dá)摩' where userName='damo'"); #刪除數(shù)據(jù) // $db->NOQuery("delete from users where userName='達(dá)摩'"); $result=$db->GetQuery("select * from users"); ?> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> <table class="table table-hover table-bordered"><tr class="info"><th>編號</th><th>用戶名</th><th>密碼</th><th>愛好</th></tr><?php foreach ($result as $rows) {?><tr><td><?php echo $rows["id"]?></td><td><?php echo $rows["userName"]?></td><td><?php echo $rows["passWord"]?></td><td><?php echo $rows["likes"]?></td></tr><?php }?> </table>總結(jié)
以上是生活随笔為你收集整理的php_DBHelper的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: jQuery经典案例【倒计时】
- 下一篇: php双分支语句【三个数排序】