欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

PHP数据库操作类mysql/mssql/access

程序员文章站 2024-01-07 14:16:10
...
<?php
class db_factory{
    // The parameterized factory method
    public static function create($type, $cached=false)
    {
		$cache_name=null;
		if($cached){
			$cache_name = '_cache';
        }
		if(file_exists('Drivers/db_' . $type . $cache_name . '.class.php')) {
			include_once 'Drivers/db_' . $type . $cache_name . '.class.php';
			$classname = 'db_' . $type;
			return new $classname;
		}else{
			die('Driver file not found,please check your file!');
		}
    }
}
// Load a MySQL Driver
//$mysql = db_factory::create('mysql');

// Load an mssql Driver
//$mssql = db_factory::create('mssql');
?>

 

 

<?php
function mssql_insert_id() {
	$id = 0;
	$res = mssql_query("SELECT @@identity AS id");
	if ($row = mssql_fetch_array($res, MSSQL_ASSOC)) {
		$id = $row["id"];
	}
	return $id;
}
?>

 

调用方法:

 

<?php
include 'db_factory.class.php';
$sql_manager = db_factory::create('mssql');
$sql_manager->connect ( '127.0.0.1,1433', 'sa', '123456', 'MII_hk' );
/*
$result = $sql_manager->select ('guestbook');
//$r = $this->get_one('',' COUNT(*) AS num');
$info=array(
db_title=>'zlsky',
password=>'zlsky',
);   
$result = $sql_manager->insert ($info,'guestbook');

$info=array(db_title=>'测试');
$sql_manager->update($info,'guestbook','uid=245');

$sql_manager->delete('guestbook','uid=246');
*/
//sql server 兼容mysql的分页方法通过limit()实现的
$sql ="select DISTINCT VIPEMailAddress from RPMIItbVIP limit 0,10";
$query = $sql_manager->query($sql);
$list = array();
while($result = $sql_manager->fetch_array($query)){
	$list[]= $result;
}
echo "<pre>";
print_r($list);
?>

上一篇:

下一篇: