MYSQL_基本实例_mysql

<?php

error_reporting(E_ALL & ~E_DEPRECATED);


$db_conf=array(

'host'=>'127.0.0.1',

'pass'=>'root',

'user'=>'root',

'name'=>'test',

);

$db=array();

$db['conn'] = mysql_connect($db_conf['host'], $db_conf['user'], $db_conf['pass']) or die("connect failed: " . mysql_error());  

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']);


你可能感兴趣的:(MYSQL_基本实例_mysql)