Mysql_Db.object
上传用户:xiao730204
上传日期:2007-01-04
资源大小:141k
文件大小:4k
- <?php
- class Mysql_Db extends BaseObject {
- var $db;
- var $debug;
- var $db_connection_handle;
- var $connection_init;
- Function Mysql_Db( $db_config = '' ) {
- $this->BaseObject( 'Mysql_Db' );
- if ( is_object( $db_config ) ) {
- $this->db = $db_config;
- } else {
- $this->db = new DbDefaults();
- }
- $this->debug = new Debug();
- $this->debug->prefix = 'Mysql_Db::MAIN';
- $this->debug->Off();
- $this->db_connection_handle = false;
- $this->connection_init = false;
- } /* END Mysql_Db() */
- Function BuildConnectString() {
- if ( $this->db->connect_string == '' ) {
- $this->db->Build_MysqlConnectString();
- }
- } /* END BuildConnectionString */
- Function CreateConnection() {
- $this->BuildConnectString();
- if (
- $this->db->persistent_mode == true &&
- $this->connection_init == false ) {
- $open_connection = 0;
- /* Open the connection to the database */
- $open_connection =
- (
- $this->db_connection_handle = @mysql_pconnect(
- $this->db->connect_string,
- $this->db->user_name,
- $this->db->password )
- );
- if ( !( $open_connection) ) {
- $this->debug->Message(
- 'Database Invalid Username / Password Combo : ' . "n" .
- 'Db Connect string : ' . $this->db->connect_string . "n" .
- 'Db Username : ' . $this->db->user_name . "n" .
- 'Db Password : ' . $this->db->password . "n"
- );
- return
- array(
- false,
- 'Invalid username / password combonation.'
- );
- }
- /* Switch to the database for that connection */
- if ( ! $this->SelectDb() ) {
- $this->debug->Message(
- 'Database select failed, check for database existance ' .
- 'or misconfiguration.' . "n" .
- 'Db Database : ' . $this->db->db_name
- );
- return array(
- false,
- 'Select database : ' .
- $this->db->db_name .
- ' failed, check for database existance, ' .
- 'or misconfiguration'
- );
- }
- $this->connection_init = true;
- return array( true, $this->db_connection_handle );
- }
- if (
- $this->db->persistent_mode == true &&
- $this->connection_init == true ) {
- return array( $this->db_connection_handle );
- }
- } /* END CreateConnection() */
- Function Open() { return $this->CreateConnection(); }
- Function DestroyConnection() {
- if ( $this->connection_init == true ) {
- if ( @mysql_close( $this->db_connection_handle ) ) {
- return array( true );
- } else {
- return array( false );
- }
- }
- }
- Function Close() { return $this->DestroyConnection(); }
- Function PrepareSql( $sql_stmt ) {
- $temp = new Mysql_DbDriver();
- /* This is here to prevent the persistent connection
- from forgetting about which database it just used */
- $this->SelectDb();
- $temp->db_connection_handle = $this->db_connection_handle;
- $temp->sql_statement = $sql_stmt;
- $temp->debug->debug = $this->debug->debug;
- return $temp;
- }
- Function SelectDb() {
- $select_db =
- (
- $db_test = @mysql_select_db(
- $this->db->db_name,
- $this->db_connection_handle )
- );
- return $select_db;
- }
- Function Prepare( $sql_stmt ) {
- return $this->PrepareSql( $sql_stmt );
- }
- Function ListAllTables() {
- if (
- $result = @mysql_listtables(
- $this->db->db_name,
- $this->db_connection_handle
- ) ) {
- $my_arr = Array();
- $i = 0;
- while( $i < @mysql_num_rows( $result ) ) {
- $my_arr[ $i ] = @mysql_tablename( $result, $i );
- $i++;
- }
- return Array( true, $my_arr );
- } else {
- return Array( false, @mysql_error() );
- }
- }
- } /* END Mysql_Db class */
- ?>