php db類庫進行數(shù)據(jù)庫操作
更新時間:2009年03月19日 01:23:46 作者:
前提是必須安裝db類庫包
復(fù)制代碼 代碼如下:
<?php
require_once "DB.php"; //包含類庫文件
$conn = DB::connect("mysql://root:1981427@localhost/test"); //連接數(shù)據(jù)庫
if (!DB::isError($conn)) { //判斷是否連接成功
print "數(shù)據(jù)庫連接成功";
}
else
{
echo "數(shù)據(jù)庫連接失??!";
}
?>
復(fù)制代碼 代碼如下:
<?php
require_once "DB.php";
$conn = DB::connect("mysql://root:1981427@localhost/test"); //調(diào)用connect連接數(shù)據(jù)庫
if (DB::isError($conn)) //如果連接出錯則報錯
{
print "數(shù)據(jù)庫連接失敗";
}
$rs = $conn->query("select id,username, password from tablename1"); //執(zhí)行SQL語句
if (DB::isError($rs)) //判斷是否執(zhí)行成功
{
print "數(shù)據(jù)查詢失敗";
}
while ($rs->fetchInto($rows)) //循環(huán)輸出查詢結(jié)果
{
print "編號號:$rows[0]<BR>";
print "姓名:$rows[1]<BR>";
print "密碼:$rows[2]<BR>";
print "<HR>";
}
?>
復(fù)制代碼 代碼如下:
<?php
require_once "DB.php";
$conn = DB::connect("mysql://root:1981427@localhost/test"); //調(diào)用connect連接數(shù)據(jù)庫
if (DB::isError($conn)) //如果連接出錯則報錯
{
print "數(shù)據(jù)庫連接失敗";
}
//執(zhí)行SQL語句,從第0條開始返回1條記錄
$rs = $conn->limitQuery("select id,username, password from tablename1",2,5); //查詢出記錄集中第三個到第六個數(shù)據(jù)
if (DB::isError($rs)) //如果查詢出錯則報錯
{
print "數(shù)據(jù)查詢失敗";
}
while ($rs->fetchInto($rows)) //循環(huán)輸出查詢結(jié)果
{
print "編號:$rows[0]<BR>";
print "姓名:$rows[1]<BR>";
print "密碼:$rows[2]<BR>";
print "<HR>";
}
?>
復(fù)制代碼 代碼如下:
<?php
require_once "DB.php";
$conn = DB::connect("mysql://root:1981427@localhost/test"); //連接數(shù)據(jù)庫
if (DB::isError($conn))
{
print "數(shù)據(jù)庫連接失敗";
}
//使用prepare函數(shù)準備SQL語句
$rs = $conn->prepare("update tablename1 set password = 'Susan' where id = '1'");
if (DB::isError($rs))
{
print "數(shù)據(jù)更新失敗";
}
else
{
$conn->execute($rs); //執(zhí)行SQL語句更新數(shù)據(jù)庫
print "數(shù)據(jù)更新成功";
}
?>
您可能感興趣的文章:
- php封裝db類連接sqlite3數(shù)據(jù)庫的方法實例
- PHP基于MySQLI函數(shù)封裝的數(shù)據(jù)庫連接工具類【定義與用法】
- PHP數(shù)據(jù)庫表操作的封裝類及用法實例詳解
- PHP封裝的PDO數(shù)據(jù)庫操作類實例
- PHP數(shù)據(jù)庫處理封裝類實例
- php簡單數(shù)據(jù)庫操作類的封裝
- PHP封裝mysqli基于面向?qū)ο蟮膍ysql數(shù)據(jù)庫操作類與用法示例
- PHP封裝的mysqli數(shù)據(jù)庫操作類示例
- PHP模型Model類封裝數(shù)據(jù)庫操作示例
- PHP封裝的數(shù)據(jù)庫模型Model類完整示例【基于PDO】
- PHP封裝類似thinkphp連貫操作數(shù)據(jù)庫Db類與簡單應(yīng)用示例
相關(guān)文章
用PHP連mysql和oracle數(shù)據(jù)庫性能比較
用PHP連mysql和oracle數(shù)據(jù)庫性能比較...2006-10-10
PHP PDOStatement::getColumnMeta講解
今天小編就為大家分享一篇關(guān)于PHP PDOStatement::getColumnMeta講解,小編覺得內(nèi)容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧2019-02-02

