<?phpphp
error_reporting(E_ALL & ~E_DEPRECATED);mysql
$db_conf=array(sql
'host'=>'127.0.0.1',fetch
'pass'=>'root',spa
'user'=>'root',it
'name'=>'test',test
);select
$db=array();error
$db['conn'] = mysql_connect($db_conf['host'], $db_conf['user'], $db_conf['pass']) or die("connect failed: " . mysql_error()); db
mysql_select_db($db_conf['name'], $db['conn']) or die ("select db failed: " . mysql_error());
//單條讀取
$db['sql']="SELECT * FROM tt_user where username='aaa' LIMIT 0,1";
$db['result']=mysql_query($db['sql'],$db['conn']) or die ("mysql_query failed: " . mysql_error());
$db_row=mysql_fetch_row($db['result'],MYSQL_ASSOC);
print_r($db_row);
//多條讀取
$db['sql']='SELECT * FROM tt_user LIMIT 0,10';
$db['result']=mysql_query($db['sql'],$db['conn']);
while ($db_row=mysql_fetch_array($db['result'],MYSQL_ASSOC)){
print_r($db_row);
}
//關閉鏈接
mysql_free_result($db['result']);
mysql_close($db['conn']);