1.mysql

$dbc=mysql_connect('localhost',$user,$pass) or die('error!');
mysql_select_db("testdb", $dbc);
mysql_query("SET NAMES 'utf8'");
$query="select * from `testtable`";
$result=mysql_query($query,$dbc) or die('wrong');
while($row = mysql_fetch_array($result, MYSQL_ASSOC)){
  print_r($row);
}
	

2.mysqli


3.pdo

try {
    $dbh = new PDO('mysql:host=localhost;dbname=testdb;charset=UTF8', $user, $pass);
    foreach($dbh->query('SELECT * from testtable') as $row) {
        print_r($row);
    }
    $dbh = null;
} catch (PDOException $e) {
    print "Error!: " . $e->getMessage() . "<br/>";
    die();
}
作者 铁血 汉子 2017年12月30日
2018/04/27/06:18:15am 2017/12/30/14:05:33
0 282