自己最常用的MYSQL操作类
<?php class mysql { public $fetch_mode = MYSQL_BOTH; public $record = array( ); public $count = NULL; public function __construct( ) { $this->connect( ); } public function connect( ) { if ( !( $this->link = mysql_connect( DB_HOST, DB_USER, DB_PASS ) ) ) { exit( mysql_error( ) ); } mysql_query( "SET NAMES UTF8" ); if ( !mysql_select_db( DB_DATE, $this->link ) ) { exit( "未能找到数据库:".DB_DATE ); } } public function ping( ) { if ( !mysql_ping( $this->link ) ) { mysql_close( $this->link ); $this->connect( ); } } public function query( $sql ) { mysql_query( "SET NAMES UTF8" ); return mysql_query( $sql ); } public function num_rows( $result ) { return mysql_num_rows( $result ); } public function affected_rows( ) { return mysql_affected_rows( ); } public function num_fields( $result ) { return mysql_num_fields( $result ); } public function free_result( $result ) { return mysql_free_result( $result ); } public function insert_id( ) { return mysql_insert_id( ); } public function close( ) { return mysql_close( ); } public function fetch_array( $result ) { if ( $result ) { return mysql_fetch_array( $result, $this->fetch_mode ); } } public function fetch_row( $rs ) { $this->record = mysql_fetch_array( $rs, $this->fetch_mode ); return $this->record; } public function fetch_all( $rs ) { $arr = array( ); while ( $this->record = mysql_fetch_array( $rs, $this->fetch_mode ) ) { $arr[] = $this->record; } return $arr; } } ?>