php mysql帮助类,基于PHP的MYSQL操作类

自己最常用的MYSQL操作类

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;

}

}

?>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值