1
header( "Content-Type: text/html; Charset=euc-jp" ); header( "Expires: Wed, 31 May 2000 14:59:58 GMT" ); ini_set( 'display_errors', "1" ); ini_set( 'error_reporting', E_ALL & ~E_NOTICE ); if ( (substr(phpversion(),0,1) + 0) == 4 ) { require_once( "db_php4.php" ); } else { require_once( "db_php5.php" ); } $conf_db_type = 1; // MySQL $conf_client_charset = "euc-jp"; if ( $_GET['send'] == '送信' ) { $conf_db_charset = $_GET['charset']; $SQL = new DB( $_GET['fld1'], $_GET['fld2'], $_GET['fld3'], $_GET['fld4'] ); if ( $SQL->Connect === false ) { $msg_string = "接続できませんでした
\n"; $msg_string .= $SQL->Error; } else { $msg_string = "接続されました
\n"; $Column = $SQL->QueryEx( "show tables" ); while ( $Column ) { $data_string .= print_r( $Column, true ); $Column = $SQL->QueryEx( ); } $SQL->Close(); } } ?>
MySQLの接続テスト
php のバージョン : print phpversion() ?>
message
= $msg_string ?>
db charset
>euc-jp
>shift_jis
>utf-8
server
database
user
password
備考
行を返さない SQL は、$SQL->Execute( $Query );
= $data_string ?>
1
# ********************************************************** # database class ( 2008/03/04 ) php4 # ********************************************************** class DB { var $Connect; var $Result; var $nField; var $nRow; var $Debug; var $Error; var $Work; var $Oracle; var $Cn; var $Rs; var $ConnectionString; var $Excel; # ********************************************************** # # ********************************************************** function DB( $Server='default', $DbName='default', $User='default', $Password='default' ) { $Server = $Server == 'default' ? $GLOBALS['conf_db_host'] : $Server; $DbName = $DbName == 'default' ? $GLOBALS['conf_db_db'] : $DbName; $User = $User == 'default' ? $GLOBALS['conf_db_user'] : $User; $Password = $Password == 'default' ? $GLOBALS['conf_db_pass'] : $Password; switch( $GLOBALS['conf_db_type'] ) { // MySQL case 1: $Server = $Server == '' ? 'localhost' : $Server; $DbName = $DbName == '' ? 'lightbox' : $DbName; $User = $User == '' ? 'root' : $User; $this->Connect = @mysql_connect( $Server, $User, $Password ); if ( !$this->Connect ) { $this->Error = mysql_error() . "
"; $this->Error .= "PHP version --> " . phpversion() . "
"; $this->Error .= "
dbmysql_connect
"; $this->Error .= __FILE__ . "
"; $this->Error .= "FUNCTION -->" . __FUNCTION__ . "
"; $this->Error .= "CLASS --> " .__CLASS__ . "
"; if ( substr( phpversion(), 0, 1 )+0 > 4 ) { $this->Error .= "METHOD --> " . __METHOD__ . "
"; } else { $this->Error .= "METHOD --> ? : use php5
"; } return; } mysql_select_db( $DbName, $this->Connect ); if ( $GLOBALS['conf_db_connect_action'] != '' ) { mysql_query( $GLOBALS['conf_db_connect_action'], $this->Connect ); } break; // SQLServer case 2: $Server = $Server == '' ? '127.0.0.1' : $Server; $DbName = $DbName == '' ? 'lightbox' : $DbName; $User = $User == '' ? 'sa' : $User; if ( !extension_loaded( "mssql" ) ) { dl("php_mssql.dll"); } $this->Connect = mssql_connect( $Server, $User, $Password ); mssql_select_db( $DbName, $this->Connect ); if ( $GLOBALS['conf_db_connect_action'] != '' ) { mssql_query( $GLOBALS['conf_db_connect_action'], $this->Connect ); } break; // PostgreSQL case 3: $Server = $Server == '' ? 'localhost' : $Server; $DbName = $DbName == '' ? 'lightbox' : $DbName; $User = $User == '' ? 'lightbox' : $User; if ( !extension_loaded( "pgsql" ) ) { dl("php_pgsql.dll"); } $this->Connect = pg_connect( "host=$Server" . " port=5432" . " dbname=$DbName" . " user=$User" . " password=$Password" ); if ( $GLOBALS['conf_db_connect_action'] != '' ) { pg_query( $this->Connect, $GLOBALS['conf_db_connect_action'] ); } break; // use COM for MDB ( PHP5 ) case 4: $this->Cn = new COM( "ADODB.Connection" ); $this->Cn->CursorLocation = 3; $this->Rs = new COM( "ADODB.Recordset" ); $Server = $Server == '' ? realpath( "hanbaib.mdb" ) : $Server; $this->ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;"; $this->ConnectionString .= "Data Source=$Server;"; if ( $this->Excel != "" ) { $this->ConnectionString .= 'Extended Properties="Excel 8.0;IMEX=1;";'; } // try { $this->Cn->Open( $this->ConnectionString ); if ( $GLOBALS['conf_db_connect_action'] != '' ) { $this->Cn->Execute( $GLOBALS['conf_db_connect_action'] ); } // } // catch (Exception $e) { // $this->Error = $e->getMessage(); // $this->Connect = false; // } break; case 7: $this->Cn = new COM( "ADODB.Connection" ); $this->Cn->CursorLocation = 3; $this->Rs = new COM( "ADODB.Recordset" ); $Server = $Server == '' ? realpath( "hanbaib.mdb" ) : $Server; $this->ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;"; $this->ConnectionString .= "Data Source=$Server;"; $this->Excel = 'Extended Properties="Excel 8.0;IMEX=1;";'; $this->ConnectionString .= $this->Excel; // try { $this->Cn->Open( $this->ConnectionString ); if ( $GLOBALS['conf_db_connect_action'] != '' ) { $this->Cn->Execute( $GLOBALS['conf_db_connect_action'] ); } // } // catch (Exception $e) { // $this->Error = $e->getMessage(); // $this->Connect = false; // } $GLOBALS['conf_db_type'] = 4; break; // use COM for Oracle (it depends on ODBC driver) case 5: $this->Cn = new COM( "ADODB.Connection" ); $this->Cn->CursorLocation = 3; $this->Rs = new COM( "ADODB.Recordset" ); $this->ConnectionString = "Provider=MSDASQL;"; $this->ConnectionString .= "DSN=$Server;"; $this->ConnectionString .= "UID=$User;"; $this->ConnectionString .= "PWD=$Password;"; $this->Cn->Open( $this->ConnectionString ); if ( $GLOBALS['conf_db_connect_action'] != '' ) { $this->Cn->Execute( $GLOBALS['conf_db_connect_action'] ); } break; // Oracle OO4O case 6: $this->Oracle = new COM( "OracleInProcServer.XOraSession" ); $this->Cn = $this->Oracle->OpenDatabase($Server, "$User/$Password", 0); # OraDatabase.CreateDynaset(SqlQuery,2) if ( $GLOBALS['conf_db_connect_action'] != '' ) { $this->Cn->ExecuteSQL( $GLOBALS['conf_db_connect_action'] ); } break; } $this->Debug = FALSE; } # ********************************************************** # # ********************************************************** function Close( ) { switch( $GLOBALS['conf_db_type'] ) { case 1: mysql_close( $this->Connect ); break; case 2: mssql_close( $this->Connect ); break; case 3: pg_close( $this->Connect ); break; case 4: case 5: # @$this->Rs->Close(); @$this->Cn->Close(); break; } } # ********************************************************** # # ********************************************************** function Query( $SqlQuery ) { if ( $GLOBALS['conf_db_charset'] != '' ) { $SqlQuery = mb_convert_encoding( $SqlQuery, $GLOBALS['conf_db_charset'], $GLOBALS['conf_client_charset'] ); } switch( $GLOBALS['conf_db_type'] ) { case 1: $ret = mysql_query( $SqlQuery,$this->Connect ); if ( $this->Debug ) { if ( mysql_errno() != 0 ) { print "
" . mysql_error() . "
"; } } break; case 2: $ret = mssql_query( $SqlQuery,$this->Connect ); break; case 3: $ret = pg_query( $this->Connect, $SqlQuery ); break; case 4: // try { $this->Rs->Open( $SqlQuery, $this->Cn ); $ret = !$this->Rs->EOF; // } // catch (Exception $e) { // $ret = false; // $this->Error = $e->getMessage(); // } break; case 5: if ( $this->Rs->State >= 1 ) { $this->Rs->Close(); } $this->Rs->Open( $SqlQuery, $this->Cn ); $ret = !$this->Rs->EOF; break; case 6: // try { $this->Rs = $this->Cn->CreateDynaset($SqlQuery,2); $ret = !$this->Rs->EOF; // } // catch (Exception $e) { // $this->Error = $e->getMessage(); // } break; } return $ret; } # ********************************************************** # # ********************************************************** function Fetch( $Result ) { switch( $GLOBALS['conf_db_type'] ) { case 1: $ret = mysql_fetch_array( $Result ); break; case 2: $ret = mssql_fetch_array( $Result ); break; case 3: $ret = pg_fetch_array( $Result ); break; case 4: case 5: case 6: $ret = array(); for( $i = 0; $i < $this->Rs->Fields->count; $i++ ) { if ( $this->Rs->Fields[$i]->type == 7 ) { if ( substr(phpversion(),0,1) == '4' ) { $test = date( "H:i:s", $this->Rs->Fields[$i]->value ); if ( $test == "00:00:00" ) { $ret[$i] = date( "Y/m/d", $this->Rs->Fields[$i]->value ); $ret[$this->Rs->Fields[$i]->name] = date( "Y/m/d", $this->Rs->Fields[$i]->value ); } else { $ret[$i] = date( "Y/m/d H:i:s", $this->Rs->Fields[$i]->value ); $ret[$this->Rs->Fields[$i]->name] = date( "Y/m/d H:i:s", $this->Rs->Fields[$i]->value ); } } else { $ret[$i] = $this->Rs->Fields[$i]->value; $ret[$this->Rs->Fields[$i]->name] = $this->Rs->Fields[$i]->value; } } else { $ret[$i] = $this->Rs->Fields[$i]->value; $ret[$this->Rs->Fields[$i]->name] = $this->Rs->Fields[$i]->value; } } break; } if ( $GLOBALS['conf_db_charset'] != '' ) { if ( $ret ) { $ret2 = array(); while (list($Key, $Value) = @each($ret)) { $ret2[$Key] = mb_convert_encoding( $Value, $GLOBALS['conf_client_charset'], $GLOBALS['conf_db_charset'] ); $Key2 = mb_convert_encoding( $Key, $GLOBALS['conf_client_charset'], $GLOBALS['conf_db_charset'] ); $ret2[$Key2] = mb_convert_encoding( $Value, $GLOBALS['conf_client_charset'], $GLOBALS['conf_db_charset'] ); } } } else { $ret2 = $ret; } return $ret2; } # ********************************************************** # # ********************************************************** function FieldName( $idx ) { switch( $GLOBALS['conf_db_type'] ) { case 1: $ret = mysql_field_name ( $this->Result, $idx ); break; case 2: $ret = mssql_field_name ( $this->Result, $idx ); break; case 3: $ret = pg_field_name( $this->Result, $idx ); break; case 4: case 5: case 6: $ret = $this->Rs->Fields[$idx]->name; break; } if ( $GLOBALS['conf_db_charset'] != '' ) { $ret = mb_convert_encoding( $ret, $GLOBALS['conf_client_charset'], $GLOBALS['conf_db_charset'] ); } return $ret; } # ********************************************************** # # ********************************************************** function QueryEx( $SqlQuery='' ) { if ( $SqlQuery != '' ) { if ( $this->Debug ) { print "
"; print "
" . $this->Arrange($SqlQuery) . "
"; print "
"; } if ( $GLOBALS['conf_db_type'] == 4 || $GLOBALS['conf_db_type'] == 5 ) { if ( substr( $SqlQuery, 0, 7 ) == "COLUMNS" ) { $table_name = Explode( " ", $SqlQuery ); $this->Rs = $this->Cn->OpenSchema( 4 ); if ( $GLOBALS['conf_db_charset'] != '' ) { $tbl = mb_convert_encoding( $table_name[1], $GLOBALS['conf_db_charset'], $GLOBALS['conf_client_charset'] ); } else { $tbl = $table_name[1]; } $this->Rs->Filter = "TABLE_NAME = '" . $tbl . "'"; $this->Rs->Sort = "ORDINAL_POSITION"; } else { $this->Result = $this->Query( $SqlQuery ); if ( !$this->Result ) { return FALSE; } } } else { $this->Result = $this->Query( $SqlQuery ); if ( !$this->Result ) { return FALSE; } } switch( $GLOBALS['conf_db_type'] ) { case 1: $this->nField = mysql_num_fields( $this->Result ); $this->nRow = mysql_num_rows ( $this->Result ); break; case 2: $this->nField = mssql_num_fields( $this->Result ); $this->nRow = mssql_num_rows ( $this->Result ); break; case 3: $this->nField = pg_num_fields( $this->Result ); $this->nRow = pg_num_rows( $this->Result ); break; case 4: case 5: case 6: $this->nField = $this->Rs->Fields->count; $this->nRow = $this->Rs->RecordCount; break; } return $this->Fetch ( $this->Result ); } else { if ( $GLOBALS['conf_db_type'] == 4 || $GLOBALS['conf_db_type'] == 5 || $GLOBALS['conf_db_type'] == 6 ) { $this->Rs->MoveNext(); if ( $this->Rs->EOF ) { return FALSE; } } return $this->Fetch ( $this->Result ); } } # ********************************************************** # # ********************************************************** function Execute( $SqlExec ) { switch( $GLOBALS['conf_db_type'] ) { case 1: if ( $this->Debug ) { print "
"; print "
" . $this->Arrange($SqlExec) . "
"; print "
"; if ( mysql_errno() != 0 ) { print "
" . mysql_error() . "
"; } } if ( $GLOBALS['conf_db_charset'] != '' ) { $SqlExec = mb_convert_encoding( $SqlExec, $GLOBALS['conf_db_charset'], $GLOBALS['conf_client_charset'] ); } $ret = mysql_query( $SqlExec,$this->Connect ); break; case 2: if ( $this->Debug ) { print "
"; print "
" . $this->Arrange($SqlExec) . "
"; print "
"; } if ( $GLOBALS['conf_db_charset'] != '' ) { $SqlExec = mb_convert_encoding( $SqlExec, $GLOBALS['conf_db_charset'], $GLOBALS['conf_client_charset'] ); } $ret = mssql_query( $SqlExec,$this->Connect ); break; case 3: if ( $this->Debug ) { print "
"; print "
" . $this->Arrange($SqlExec) . "
"; print "
"; } if ( $GLOBALS['conf_db_charset'] != '' ) { $SqlExec = mb_convert_encoding( $SqlExec, $GLOBALS['conf_db_charset'], $GLOBALS['conf_client_charset'] ); } $ret = pg_query( $this->Connect, $SqlExec ); break; case 4: case 5: case 6: if ( $this->Debug ) { print "
"; print "
" . $this->Arrange($SqlExec) . "
"; print "
"; } if ( $GLOBALS['conf_db_charset'] != '' ) { $SqlExec = mb_convert_encoding( $SqlExec, $GLOBALS['conf_db_charset'], $GLOBALS['conf_client_charset'] ); } $ret = TRUE; if ( $GLOBALS['conf_db_type'] == 6 ) { // try { $this->Cn->ExecuteSQL( $SqlExec ); // } // catch (Exception $e) { // $ret = false; // $this->Error = $e->getMessage(); // } } else { // try { $this->Cn->Execute( $SqlExec ); // } // catch (Exception $e) { // $ret = false; // $this->Error = $e->getMessage(); // } } break; } return $ret; } # ********************************************************** # # ********************************************************** function Version( ) { switch( $GLOBALS['conf_db_type'] ) { case 1: $Field = $this->QueryEx( "show variables like 'version'" ); $ret = $Field[1]; break; case 2: $Field = $this->QueryEx( "sp_server_info @attribute_id = 2" ); $ret = $Field["attribute_value"]; break; case 3: $Field = $this->QueryEx( "select version()" ); $ret = $Field["version"]; break; } return $ret; } # ********************************************************** # # ********************************************************** function Arrange( $target ) { $ret = str_replace( ',', "\n\t,", $target ); $ret = str_replace( 'set ', "set\n\t", $ret ); $ret = str_replace( 'where ', "\nwhere ", $ret ); return "\n$ret"; } } ?>
1
# ********************************************************** # database class ( 2008/03/04 ) php5 # ********************************************************** class DB { var $Connect; var $Result; var $nField; var $nRow; var $Debug; var $Error; var $Work; var $Oracle; var $Cn; var $Rs; var $ConnectionString; var $Excel; # ********************************************************** # # ********************************************************** function DB( $Server='default', $DbName='default', $User='default', $Password='default' ) { $Server = $Server == 'default' ? $GLOBALS['conf_db_host'] : $Server; $DbName = $DbName == 'default' ? $GLOBALS['conf_db_db'] : $DbName; $User = $User == 'default' ? $GLOBALS['conf_db_user'] : $User; $Password = $Password == 'default' ? $GLOBALS['conf_db_pass'] : $Password; switch( $GLOBALS['conf_db_type'] ) { // MySQL case 1: $Server = $Server == '' ? 'localhost' : $Server; $DbName = $DbName == '' ? 'lightbox' : $DbName; $User = $User == '' ? 'root' : $User; $this->Connect = @mysql_connect( $Server, $User, $Password ); if ( !$this->Connect ) { $this->Error = mysql_error() . "
"; $this->Error .= "PHP version --> " . phpversion() . "
"; $this->Error .= "
dbmysql_connect
"; $this->Error .= __FILE__ . "
"; $this->Error .= "FUNCTION -->" . __FUNCTION__ . "
"; $this->Error .= "CLASS --> " .__CLASS__ . "
"; if ( substr( phpversion(), 0, 1 )+0 > 4 ) { $this->Error .= "METHOD --> " . __METHOD__ . "
"; } else { $this->Error .= "METHOD --> ? : use php5
"; } return; } mysql_select_db( $DbName, $this->Connect ); if ( $GLOBALS['conf_db_connect_action'] != '' ) { mysql_query( $GLOBALS['conf_db_connect_action'], $this->Connect ); } break; // SQLServer case 2: $Server = $Server == '' ? '127.0.0.1' : $Server; $DbName = $DbName == '' ? 'lightbox' : $DbName; $User = $User == '' ? 'sa' : $User; if ( !extension_loaded( "mssql" ) ) { dl("php_mssql.dll"); } $this->Connect = mssql_connect( $Server, $User, $Password ); mssql_select_db( $DbName, $this->Connect ); if ( $GLOBALS['conf_db_connect_action'] != '' ) { mssql_query( $GLOBALS['conf_db_connect_action'], $this->Connect ); } break; // PostgreSQL case 3: $Server = $Server == '' ? 'localhost' : $Server; $DbName = $DbName == '' ? 'lightbox' : $DbName; $User = $User == '' ? 'lightbox' : $User; if ( !extension_loaded( "pgsql" ) ) { dl("php_pgsql.dll"); } $this->Connect = pg_connect( "host=$Server" . " port=5432" . " dbname=$DbName" . " user=$User" . " password=$Password" ); if ( $GLOBALS['conf_db_connect_action'] != '' ) { pg_query( $this->Connect, $GLOBALS['conf_db_connect_action'] ); } break; // use COM for MDB ( PHP5 ) case 4: $this->Cn = new COM( "ADODB.Connection" ); $this->Cn->CursorLocation = 3; $this->Rs = new COM( "ADODB.Recordset" ); $Server = $Server == '' ? realpath( "hanbaib.mdb" ) : $Server; $this->ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;"; $this->ConnectionString .= "Data Source=$Server;"; if ( $this->Excel != "" ) { $this->ConnectionString .= 'Extended Properties="Excel 8.0;IMEX=1;";'; } try { $this->Cn->Open( $this->ConnectionString ); if ( $GLOBALS['conf_db_connect_action'] != '' ) { $this->Cn->Execute( $GLOBALS['conf_db_connect_action'] ); } } catch (Exception $e) { $this->Error = $e->getMessage(); $this->Connect = false; } break; case 7: $this->Cn = new COM( "ADODB.Connection" ); $this->Cn->CursorLocation = 3; $this->Rs = new COM( "ADODB.Recordset" ); $Server = $Server == '' ? realpath( "hanbaib.mdb" ) : $Server; $this->ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;"; $this->ConnectionString .= "Data Source=$Server;"; $this->Excel = 'Extended Properties="Excel 8.0;IMEX=1;";'; $this->ConnectionString .= $this->Excel; try { $this->Cn->Open( $this->ConnectionString ); if ( $GLOBALS['conf_db_connect_action'] != '' ) { $this->Cn->Execute( $GLOBALS['conf_db_connect_action'] ); } } catch (Exception $e) { $this->Error = $e->getMessage(); $this->Connect = false; } $GLOBALS['conf_db_type'] = 4; break; // use COM for Oracle (it depends on ODBC driver) case 5: $this->Cn = new COM( "ADODB.Connection" ); $this->Cn->CursorLocation = 3; $this->Rs = new COM( "ADODB.Recordset" ); $this->ConnectionString = "Provider=MSDASQL;"; $this->ConnectionString .= "DSN=$Server;"; $this->ConnectionString .= "UID=$User;"; $this->ConnectionString .= "PWD=$Password;"; $this->Cn->Open( $this->ConnectionString ); if ( $GLOBALS['conf_db_connect_action'] != '' ) { $this->Cn->Execute( $GLOBALS['conf_db_connect_action'] ); } break; // Oracle OO4O case 6: $this->Oracle = new COM( "OracleInProcServer.XOraSession" ); $this->Cn = $this->Oracle->OpenDatabase($Server, "$User/$Password", 0); # OraDatabase.CreateDynaset(SqlQuery,2) if ( $GLOBALS['conf_db_connect_action'] != '' ) { $this->Cn->ExecuteSQL( $GLOBALS['conf_db_connect_action'] ); } break; } $this->Debug = FALSE; } # ********************************************************** # # ********************************************************** function Close( ) { switch( $GLOBALS['conf_db_type'] ) { case 1: mysql_close( $this->Connect ); break; case 2: mssql_close( $this->Connect ); break; case 3: pg_close( $this->Connect ); break; case 4: case 5: # @$this->Rs->Close(); @$this->Cn->Close(); break; } } # ********************************************************** # # ********************************************************** function Query( $SqlQuery ) { if ( $GLOBALS['conf_db_charset'] != '' ) { $SqlQuery = mb_convert_encoding( $SqlQuery, $GLOBALS['conf_db_charset'], $GLOBALS['conf_client_charset'] ); } switch( $GLOBALS['conf_db_type'] ) { case 1: $ret = mysql_query( $SqlQuery,$this->Connect ); if ( $this->Debug ) { if ( mysql_errno() != 0 ) { print "
" . mysql_error() . "
"; } } break; case 2: $ret = mssql_query( $SqlQuery,$this->Connect ); break; case 3: $ret = pg_query( $this->Connect, $SqlQuery ); break; case 4: try { $this->Rs->Open( $SqlQuery, $this->Cn ); $ret = !$this->Rs->EOF; } catch (Exception $e) { $ret = false; $this->Error = $e->getMessage(); } break; case 5: if ( $this->Rs->State >= 1 ) { $this->Rs->Close(); } $this->Rs->Open( $SqlQuery, $this->Cn ); $ret = !$this->Rs->EOF; break; case 6: try { $this->Rs = $this->Cn->CreateDynaset($SqlQuery,2); $ret = !$this->Rs->EOF; } catch (Exception $e) { $this->Error = $e->getMessage(); } break; } return $ret; } # ********************************************************** # # ********************************************************** function Fetch( $Result ) { switch( $GLOBALS['conf_db_type'] ) { case 1: $ret = mysql_fetch_array( $Result ); break; case 2: $ret = mssql_fetch_array( $Result ); break; case 3: $ret = pg_fetch_array( $Result ); break; case 4: case 5: case 6: $ret = array(); for( $i = 0; $i < $this->Rs->Fields->count; $i++ ) { if ( $this->Rs->Fields[$i]->type == 7 ) { if ( substr(phpversion(),0,1) == '4' ) { $test = date( "H:i:s", $this->Rs->Fields[$i]->value ); if ( $test == "00:00:00" ) { $ret[$i] = date( "Y/m/d", $this->Rs->Fields[$i]->value ); $ret[$this->Rs->Fields[$i]->name] = date( "Y/m/d", $this->Rs->Fields[$i]->value ); } else { $ret[$i] = date( "Y/m/d H:i:s", $this->Rs->Fields[$i]->value ); $ret[$this->Rs->Fields[$i]->name] = date( "Y/m/d H:i:s", $this->Rs->Fields[$i]->value ); } } else { $ret[$i] = $this->Rs->Fields[$i]->value; $ret[$this->Rs->Fields[$i]->name] = $this->Rs->Fields[$i]->value; } } else { $ret[$i] = $this->Rs->Fields[$i]->value; $ret[$this->Rs->Fields[$i]->name] = $this->Rs->Fields[$i]->value; } } break; } if ( $GLOBALS['conf_db_charset'] != '' ) { if ( $ret ) { $ret2 = array(); while (list($Key, $Value) = @each($ret)) { $ret2[$Key] = mb_convert_encoding( $Value, $GLOBALS['conf_client_charset'], $GLOBALS['conf_db_charset'] ); $Key2 = mb_convert_encoding( $Key, $GLOBALS['conf_client_charset'], $GLOBALS['conf_db_charset'] ); $ret2[$Key2] = mb_convert_encoding( $Value, $GLOBALS['conf_client_charset'], $GLOBALS['conf_db_charset'] ); } } } else { $ret2 = $ret; } return $ret2; } # ********************************************************** # # ********************************************************** function FieldName( $idx ) { switch( $GLOBALS['conf_db_type'] ) { case 1: $ret = mysql_field_name ( $this->Result, $idx ); break; case 2: $ret = mssql_field_name ( $this->Result, $idx ); break; case 3: $ret = pg_field_name( $this->Result, $idx ); break; case 4: case 5: case 6: $ret = $this->Rs->Fields[$idx]->name; break; } if ( $GLOBALS['conf_db_charset'] != '' ) { $ret = mb_convert_encoding( $ret, $GLOBALS['conf_client_charset'], $GLOBALS['conf_db_charset'] ); } return $ret; } # ********************************************************** # # ********************************************************** function QueryEx( $SqlQuery='' ) { if ( $SqlQuery != '' ) { if ( $this->Debug ) { print "
"; print "
" . $this->Arrange($SqlQuery) . "
"; print "
"; } if ( $GLOBALS['conf_db_type'] == 4 || $GLOBALS['conf_db_type'] == 5 ) { if ( substr( $SqlQuery, 0, 7 ) == "COLUMNS" ) { $table_name = Explode( " ", $SqlQuery ); $this->Rs = $this->Cn->OpenSchema( 4 ); if ( $GLOBALS['conf_db_charset'] != '' ) { $tbl = mb_convert_encoding( $table_name[1], $GLOBALS['conf_db_charset'], $GLOBALS['conf_client_charset'] ); } else { $tbl = $table_name[1]; } $this->Rs->Filter = "TABLE_NAME = '" . $tbl . "'"; $this->Rs->Sort = "ORDINAL_POSITION"; } else { $this->Result = $this->Query( $SqlQuery ); if ( !$this->Result ) { return FALSE; } } } else { $this->Result = $this->Query( $SqlQuery ); if ( !$this->Result ) { return FALSE; } } switch( $GLOBALS['conf_db_type'] ) { case 1: $this->nField = mysql_num_fields( $this->Result ); $this->nRow = mysql_num_rows ( $this->Result ); break; case 2: $this->nField = mssql_num_fields( $this->Result ); $this->nRow = mssql_num_rows ( $this->Result ); break; case 3: $this->nField = pg_num_fields( $this->Result ); $this->nRow = pg_num_rows( $this->Result ); break; case 4: case 5: case 6: $this->nField = $this->Rs->Fields->count; $this->nRow = $this->Rs->RecordCount; break; } return $this->Fetch ( $this->Result ); } else { if ( $GLOBALS['conf_db_type'] == 4 || $GLOBALS['conf_db_type'] == 5 || $GLOBALS['conf_db_type'] == 6 ) { $this->Rs->MoveNext(); if ( $this->Rs->EOF ) { return FALSE; } } return $this->Fetch ( $this->Result ); } } # ********************************************************** # # ********************************************************** function Execute( $SqlExec ) { switch( $GLOBALS['conf_db_type'] ) { case 1: if ( $this->Debug ) { print "
"; print "
" . $this->Arrange($SqlExec) . "
"; print "
"; if ( mysql_errno() != 0 ) { print "
" . mysql_error() . "
"; } } if ( $GLOBALS['conf_db_charset'] != '' ) { $SqlExec = mb_convert_encoding( $SqlExec, $GLOBALS['conf_db_charset'], $GLOBALS['conf_client_charset'] ); } $ret = mysql_query( $SqlExec,$this->Connect ); break; case 2: if ( $this->Debug ) { print "
"; print "
" . $this->Arrange($SqlExec) . "
"; print "
"; } if ( $GLOBALS['conf_db_charset'] != '' ) { $SqlExec = mb_convert_encoding( $SqlExec, $GLOBALS['conf_db_charset'], $GLOBALS['conf_client_charset'] ); } $ret = mssql_query( $SqlExec,$this->Connect ); break; case 3: if ( $this->Debug ) { print "
"; print "
" . $this->Arrange($SqlExec) . "
"; print "
"; } if ( $GLOBALS['conf_db_charset'] != '' ) { $SqlExec = mb_convert_encoding( $SqlExec, $GLOBALS['conf_db_charset'], $GLOBALS['conf_client_charset'] ); } $ret = pg_query( $this->Connect, $SqlExec ); break; case 4: case 5: case 6: if ( $this->Debug ) { print "
"; print "
" . $this->Arrange($SqlExec) . "
"; print "
"; } if ( $GLOBALS['conf_db_charset'] != '' ) { $SqlExec = mb_convert_encoding( $SqlExec, $GLOBALS['conf_db_charset'], $GLOBALS['conf_client_charset'] ); } $ret = TRUE; if ( $GLOBALS['conf_db_type'] == 6 ) { try { $this->Cn->ExecuteSQL( $SqlExec ); } catch (Exception $e) { $ret = false; $this->Error = $e->getMessage(); } } else { try { $this->Cn->Execute( $SqlExec ); } catch (Exception $e) { $ret = false; $this->Error = $e->getMessage(); } } break; } return $ret; } # ********************************************************** # # ********************************************************** function Version( ) { switch( $GLOBALS['conf_db_type'] ) { case 1: $Field = $this->QueryEx( "show variables like 'version'" ); $ret = $Field[1]; break; case 2: $Field = $this->QueryEx( "sp_server_info @attribute_id = 2" ); $ret = $Field["attribute_value"]; break; case 3: $Field = $this->QueryEx( "select version()" ); $ret = $Field["version"]; break; } return $ret; } # ********************************************************** # # ********************************************************** function Arrange( $target ) { $ret = str_replace( ',', "\n\t,", $target ); $ret = str_replace( 'set ', "set\n\t", $ret ); $ret = str_replace( 'where ', "\nwhere ", $ret ); return "\n$ret"; } } ?>