|
|
|
อยากได้ Script เปลี่ยน Access เป็น SQL Server หรือ MySql ก็ได้ |
|
|
|
|
|
|
|
ผมมีแต่ mssql , mysql, oracle อะคับลองเอาไปประยุคดู
<?php
/**** Class Database ****/
Class MyDatabase
{
var $DBERROR;
/**** function connect to database ****/
// dbtype = 0 : MSSQL
// dbtype = 1 : MYSQL
// dbtype = 2 : ORACLE
function MyDatabase($dbType=0, $strHost="localhost" ,$strDB ,$strUser, $strPassword)
{
$this->dbType = $dbType;
if($dbType == 0){
$this->Connect = @mssql_connect($strHost,$strUser,$strPassword);
$this->DB = @mssql_select_db($strDB);
}else if($dbType == 1){
$this->Connect = @mysql_connect($strHost,$strUser,$strPassword);
$this->DB = @mysql_select_db($strDB);
@mysql_query("SET NAMES tis620");
}else if($dbType == 2){
$this->Connect = @OCILogon($strUser, $strPassword, $strDB);
}
}
function db_update(){
$this->strsql;
echo $this->strsql;
if($this->dbType == 0){
$rs = @mssql_query($this->strsql);
if ($rs){
return @mssql_rows_affected($this->Connect);
}else{
return -2;
}
}else if($this->dbType == 1){
$rs = @mysql_query($this->strsql);
if ($rs){
return @mysql_affected_rows();
}else{
return -2;
}
}else if($this->dbType == 2){
$rs = @OCIParse($this-Connect, $this->strsql);
$success = @OCIExecute($rs, OCI_DEFAULT);
if ($success === false)
{
$DBERROR = @implode(oci_error($rs), "\n");
return -2;
}
return $this->db_numrow($rs);
}
}
function db_query(){
if($this->dbType == 0){
return @mssql_query($this->strsql);
}else if($this->dbType == 1){
return @mysql_query($this->strsql);
}else if($this->dbType == 2){
$rs = @OCIParse($this->Connect, $this->strsql);
@OCIExecute($rs, OCI_DEFAULT);
return $rs;
}
}
function db_fetch($rs){
if($this->dbType == 0){
return @mssql_fetch_array($rs);
}else if($this->dbType == 1){
return @mysql_fetch_array($rs);
}else if($this->dbType == 2){
return @OCIFetch($rs);
}
}
/** only oracle **/
function db_result($rs, $txt)
{
return OCIResult($rs, $txt);
}
function db_numrow($rs){
if($this->dbType == 0){
return @mssql_num_rows($rs);
}else if($this->dbType == 1){
return @mysql_num_rows($rs);
}else if($this->dbType == 2){
return @OCIRowcount($rs);
}
}
function db_get($sql, $head)
{
if($this->dbType == 0){
$rs = @mssql_query($sql);
$row = @mssql_fetch_array($rs);
return $row[$head];
}else if($this->dbType == 1){
$rs = @mysql_query($sql);
$row = @mysql_fetch_array($rs);
return $row[$head];
}else if($this->dbType == 2){
$rs = @OCIParse($this->Connect, $sql);
@OCIExecute($rs, OCI_DEFAULT);
@OCIFetch($rs);
return @OCIResult($rs, $head);
}
}
function db_commit(){
if($this->dbType == 0){
return @mssql_query("commit");
}else if($this->dbType == 1){
return @mysql_query("commit");
}else if($this->dbType == 2){
return @OCICommit($this->Connect);
}
}
function db_rollback(){
if($this->dbType == 0){
return @mssql_query("rollback");
}else if($this->dbType == 1){
return @mysql_query("rollback");
}else if($this->dbType == 2){
return @OCIRollback($this->Connect);
}
}
function db_freeresult($rs){
if($this->dbType == 0){
if (!is_resource($rs))
{
echo "<pre>sqlfreeresult error
";
print_r(debug_backtrace());
echo "</pre>";
return false;
}
return @mssql_free_result($rs);
}else if($this->dbType == 1){
if (!is_resource($rs))
{
echo "<pre>sqlfreeresult error
";
print_r(debug_backtrace());
echo "</pre>";
return false;
}
return @mysql_free_result($rs);
}else if($this->dbType == 2){
if (!is_resource($rs))
{
echo "<pre>sqlfreeresult error
";
print_r(debug_backtrace());
echo "</pre>";
return false;
}
return @OCIFreestatement($rs);
}
}
function db_free($rs){
$this->db_freeresult($rs);
}
/*** end class auto disconnect ***/
function db_close() {
if($this->dbType == 0){
return @mssql_close($this->Connect);
}else if($this->dbType == 1){
return @mysql_close($this->Connect);
}else if($this->dbType == 2){
return @oci_close($this->Connect);
}
}
}// End Class
?>
|
|
|
|
|
Date :
2009-04-17 15:42:33 |
By :
windersun |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 04
|