$dbConfig = array( 'host' => '10.128.11.101', 'port' => '3306', 'user' => 'test', 'pass' => 'test', 'db' => 'test', ); $sql = 'select * from so_topic_app'; //---------mysql----------// $db = mysql_connect($dbConfig['host'], $dbConfig['user'], $dbConfig['pass']); mysql_select_db($dbConfig['db'], $db); mysql_set_charset('utf8', $db); // mysql使用buffer $res = mysql_query($sql, $db); $data = array(); while($row = mysql_fetch_row($res)) { $data[] = $row; } // mysql不使用buffer $res = mysql_unbuffered_query($sql, $db); $data = array(); while($row = mysql_fetch_row($res)) { $data[] = $row; } mysql_close($db); //---------mysqli----------// $db = mysqli_connect($dbConfig['host'], $dbConfig['user'], $dbConfig['pass'], $dbConfig['db']); // mysqli不使用buffer $result = mysqli_query($db, $sql); $data = array(); while($row = $result->fetch_array()) { $data[] = $row; } // mysqli使用buffer $result = mysqli_query($db, $sql, MYSQLI_STORE_RESULT); $data = array(); while($row = $result->fetch_array()) { $data[] = $row; } mysqli_free_result($result); mysqli_close($db); //---------pdo----------// $dsn = "mysql:dbname={$dbConfig['db']};host={$dbConfig['host']}"; $pdo = new PDO($dsn, $dbConfig['user'], $dbConfig['pass']); // pdo不使用buffer $stmt = $pdo->prepare($sql); $stmt->execute(); $data = array(); $data = $stmt->fetchAll(); // pdo使用buffer $pdo->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true); $stmt = $pdo->prepare($sql); $stmt->execute(); $data = array(); $data = $stmt->fetchAll(); |