php資料庫類及操作例項,雖然不是很強大,但是用起來還是蠻方便的
db.class.php
php**
<?php /**
*資料庫類
*/classdatabase
//資料庫連線
publicfunctionconnect()
//eof#dbconnect()
//更改資料庫
publicfunctiondbchange($db)
//執行sql語句,返回結果資源id
publicfunctionexecute($sql)
//獲取陣列-索引和關聯
publicfunctionfetcharray($resulttype=mysql_both)
//獲取關聯陣列
publicfunctionfetchassoc()
//獲取數字索引陣列
publicfunctionfetchindexarray()
//獲取物件陣列
publicfunctionfetchobject()
//返回記錄行數
functionnumrows()
//返回主機中所有資料庫名
publicfunctiondbnames()
//增functioninsert($sql)
//改functionupdate($sql)
//關閉連線
functiondbclose()
}//endclass
?>
直接引用即可:
php**
<?php include"db.class.php";
$mydb=newdatabase("localhost","root","123456","test");
$mydb->connect();
$mydb->execute("setnamesgbk");
$mydb->execute("select*fromusrs");
print_r($mydb->dbnames());
?>
php資料庫操作例項
本例是用php連線乙個mysql資料庫操作的演示,實現連線開啟乙個庫,並讀取資料的基本功能。資料庫名稱為 test 表名為 user 分別有7個字段 id userid age tel email address 伺服器 資料庫編碼 均採用 utf 8 mysql query set names g...
php 資料庫操作類
class dbconnect if dbtable this dbchange dbtable 選擇要操作的資料庫 function dbchange dbtable type 0 返回執行完sql語句後的結果 不做處理 type 1 返回 看下面注釋 type 2 返回 看下面注釋 functi...
php資料庫操作類
config.db.php db config hostname localhost 伺服器位址 db config username root 資料庫使用者名稱 db config password 123 資料庫密碼 db config database test 資料庫名稱 db config...