導航:首頁 > 編程語言 > shopconfigphp

shopconfigphp

發布時間:2025-08-17 05:33:53

A. 誰給個php操作mysql類並有詳細使用說明或例子

下面這個,是針對php5的一個簡單資料庫封裝類,適合學習,其他的如刪除、更新等操作,你可以自己加上:
<?php
class Mysql{ //首先定義一個類,首寫字母大寫
public $host;//伺服器名,訪問修飾符PUBLIC證明$host是一個公共的屬情在類的內部外部都可訪問,可以被繼承
public $user;//用戶名,是公共的屬性
private $pass;//密碼,問修飾符private證明$pass是私有的.只能在類的內部使用且不能被繼承.
public $dbname;//資料庫名,也是公共的屬性.
//__construct聲名這是一個造函數,定義一些初始的信息.有三個參數
public function __construct($host,$user,$pass,$dbname){
$this->host = $host;
$this->user = $user;
$this->pass = $pass;
$this->dbname = $dbname;
$link = @mysql_connect($this->host,$this->user,$this->pass)
or die("error");
@mysql_select_db($this->dbname,$link)
or die("error2");
}
//定義資料庫的查尋和顯示函數
function myQuery($sql){
$result = mysql_query($sql);
if(!$result){
echo "error3";
exit;
}
$num = mysql_num_rows($result);
if($num){
echo "NO".$num;
}
while($row = mysql_fetch_assoc($result)){
echo '<tr><td bgcolor="#fffddd"><pre>'.htmlspecialchars(stripslashes($row['body']))."<pre></td></tr>";
}
}
}
$rutt = new Mysql('localhost','root','ssss','calvin');//實例化一個類...記住這里的參數是和構造函數的參數一樣的...
$rutt->myQuery('select * from calvin_body');//運行資料庫查尋並顯示的函數..
?>

下面這個是針對php5以下版本的資料庫封裝類,體現了php類的繼承,一個許願版程序的:
<?php
/*
* FileName: DatabaseSQL.inc.php
* Author: Terry
* Function: 建立DatabaseSQL對象,實現對資料庫的基本操作
* Version : Blue-System v2.0
* CreateDate: 2004-03-10
* Copyright: Blue-Workshop / http://www.blue4me.net
*/

// 定義DatabaseSQL對象
Class DatabaseSQL
{
var $CONN = ""; // 連接號
var $HOST = "Localhost"; // 主機名
var $USER = ""; // 用戶名
var $PASSWORD = ""; // 密碼

// DatabaseSQL類的構造函數
function DatabaseSQL($DBNAME)
{
$user = $this -> USER;
$password = $this -> PASSWORD;
$host = $this -> HOST;
$db = $DBNAME;

// 連接資料庫
$conn = mysql_connect($host, $user, $password);
mysql_select_db($db, $conn);
$this -> CONN = $conn;
return true;
}

// 定義查詢操作
function select($strSQL = "")
{
if ( empty($strSQL) ) return false;
if ( empty($this -> CONN) ) return false;
$conn = $this -> CONN;

// 發送SQL語句,獲得結果
$result = mysql_query($strSQL, $conn);
if ( (!$result) or (empty($result)) ) {
return false;
}
$num = 0;
$data = array();
// 將查詢結果放二維數組中
while ( $row = mysql_fetch_array($result) ) {
$data[$num] = $row;
$num++;
}
mysql_free_result($result);
return $data;
}

// 定義插入操作
function insert($strSQL = "")
{
if ( empty($strSQL) ) return false;
if ( empty($this -> CONN) ) return false;
$conn = $this -> CONN;

// 發送SQL語句,插入新數據
$result = mysql_query($strSQL, $conn);
if ( !result ) return false;

// 獲得記錄的id號
$result = mysql_insert_id();
return $result;
}

// 定義更新操作
function update($strSQL = "")
{
if ( empty($strSQL) ) return false;
if ( empty($this -> CONN) ) return false;
$conn = $this -> CONN;

// 發送SQL語句,更新資料庫
$result = mysql_query($strSQL, $conn);
return $result;
}

// 定義刪除操作
function delete($strSQL = "")
{
if ( empty($strSQL) ) return false;
if ( empty($this -> CONN) ) return false;
$conn = $this -> CONN;

// 發送SQL語句,刪除記錄
$result = mysql_query($strSQL, $conn);
return $result;
}

}
?>

----------------------------------

<?php
/*
* FileName: Wish.inc.php
* Author: Terry
* Function: 建立Wish對象,實現對許願板進行操作功能
* Version : Blue-System v2.0
* CreateDate: 2004-03-10
* Copyright: Blue-Workshop / http://www.blue4me.net
*/

require "config.inc.php";
require "DatabaseSQL.inc.php";

// 定義Wish對象
Class Wish extends DatabaseSQL
{
// 構造函數
function Wish()
{
$DBName = $GLOBALS["dbname"];
$this -> DatabaseSQL($DBName);
}

// 添加新願望(use in wish/save.php?action=add_wish)
function AddWish($name,$receiver,$type,$address,$content,$hide,$addtime)
{
$strSQL = "insert into Wish (Name, Receiver, Type, Address, Content, Hide, AddTime) values ('$name', '$receiver', '$type', '$address', '$content', '$hide', '$addtime')";
$result = $this -> insert($strSQL);
return $result;
}

// 修改指定id的願望內容(use in save.php?action=edit_wish)
function EditWish($wid,$name,$receiver,$type,$address,$content,$hide)
{
$strSQL = "update `Wish` set `Name` = '$name', `Receiver` = '$receiver', `Type` = '$type', `Address` = '$address', `Content` = '$content', `Hide` = '$hide' where `WID` = '$wid' ";
$result = $this -> update($strSQL);
return $result;
}

// 願望列表(use in index.php)
function ListWish($startid,$list_nums)
{
$strSQL = "select * from Wish order by AddTime desc LIMIT $startid,$list_nums";
$result = $this -> select($strSQL);
return $result;
}

// 獲取指定願望信息(use in index.php?go=view_wish)
function GetWish($wid)
{
$strSQL = "select * from Wish where WID = '$wid'";
$result = $this -> select($strSQL);
return $result;
}

// 更新指定願望的瀏覽數(use in index.php?go=view_wish)
function UpdateHit($wid)
{
$strSQL = "update `Wish` set `Hit` = ( `Hit` + 1 ) where `WID` = '$wid'";
$result = $this -> update($strSQL);
return $result;
}

// 刪除指定願望信息(use in save.php?action=del_wish)
function DelWish($wid)
{
$strSQL = "delete from Wish where WID = '$wid'";
$result = $this -> delete($strSQL);
return $result;
}

}
?>

---------------------------------------

<?php
/*
* FileName: config.inc.php
* Author: Terry
* Function: 系統基本設置
* Version : B.S - Wish v1.0
* CreateDate: 2004-03-19
* Copyright: Blue-Workshop
* Tec-Support: http://www.blue4me.net / http://feeltouch.8u8.com
* Attention: 請保留版權信息,謝謝 ^_^
*/

// 資料庫信息
$dbhost = "Localhost"; /* 主機名 */
$dbuser = ""; /* 資料庫用戶 */
$dbpwd = ""; /* 資料庫密碼 */
$dbname = "BS_Wish"; /* 資料庫名 */

// 管理員信息
$adminname = "blue"; /* 初始化管理員 */
$adminpwd = "blue"; /* 初始化管理密碼 */
?>

閱讀全文

與shopconfigphp相關的資料

熱點內容
編譯android系統用amd平台可以嗎 瀏覽:995
程序員封板 瀏覽:945
linux取消命令 瀏覽:425
手機app被騙如何報警 瀏覽:435
上海圖紙加密質量可靠嗎 瀏覽:755
如何打開win10的伺服器地址 瀏覽:332
信息矩陣加密信息 瀏覽:703
游戲解壓後本地磁碟滿了 瀏覽:165
江蘇兼職程序員哪裡接 瀏覽:583
maclinux工具下載 瀏覽:171
女程序員那麼可愛免費 瀏覽:830
php自己實現mvc框架 瀏覽:133
phpcurl手機 瀏覽:738
python真的不如java嗎 瀏覽:458
華為編譯器有哪些 瀏覽:954
去哪裡app上報團靠譜嗎 瀏覽:397
祭奠程序員 瀏覽:998
如何把域伺服器的記錄刪除 瀏覽:32
jshaman網頁加密 瀏覽:845
雲伺服器返回指令 瀏覽:89