简单的db类
$conn_string_array = array('server'=>'127.0.0.1','user'=>'root','password'=>'1230','database'=>'finepvol'); $conn = db::connect($conn_string_array); $sql = "select name,insert_time from test"; $stmt = db::query($sql); while ($row = db::fetch_array($stmt)) { var_dump($row); }
<?php
class db { public static function connect(array $conn_string) { $conn = mysql_connect($conn_string['server'],$conn_string['user'],$conn_string['password']); mysql_select_db($conn_string['database']); return $conn; } public static function query($sql){ return mssql_query($sql); } public static function fetch_row($result){ return mssql_fetch_row($result); } public static function fetch_array($result){ return mssql_fetch_array($result); } public static function num_rows($result){ return mssql_num_rows($result); } public static function num_fields($result){ return mssql_num_fields($result); } public static function fetch_field($result){ return mssql_fetch_field($result); } public static function close(){ return mssql_close(); } } ?>