<?php $host='192.168.1.78'; $user='root'; $pwd='mil'; $db='test'; $tableName='student'; $con=mysqli_connect($host,$user,$pwd,$db); echo '<pre>'; mysqli_query($con,'set names "utf8"'); $res=mysqli_query($con,'select * from '.$tableName); while($result=mysqli_fetch_assoc($res)){ var_dump($result); } <?php /** * Created by PhpStorm. * User: 75449 * Date: 2017/12/24 * Time: 10:04 */ $username = 'root'; $password = 'michael'; $databaseName = 'laratest'; $con = mysqli_connect('localhost', $username, $password, $databaseName); mysqli_query($con,'set names "utf8"'); echo "<pre>"; // 取出某一字段放到数组内 $res = mysqli_query($con, 'SELECT migration,batch FROM migrations'); $aField = []; echo mysqli_error($con); while ($tmp = mysqli_fetch_row($res)) { $aField[] = $tmp; } var_dump($aField); /***** array(2) { [0]=> array(2) { [0]=> string(36) "2014_10_12_000000_create_users_table" [1]=> string(1) "1" } [1]=> array(2) { [0]=> string(46) "2014_10_12_100000_create_password_resets_table" [1]=> string(1) "1" } } *****/