function selecttest() { try { $pdo = new PDO("mysql:host=localhost;dbname=test", 'root', '123456'); // 不使用缓存结果集方式 // $pdo->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, false); $sth = $pdo->prepare('select * from test'); $sth->execute(); echo '最初占用内存大小:' . memory_get_usage() . "\n"; $i = 0; while ($result = $sth->fetch(PDO::FETCH_ASSOC)) { $i += 1; if ($i > 10) { break; } sleep(1); print_r($result); echo '占用内存大小:' . memory_get_usage() . "\n"; } } catch (Exception $e) { echo $e->getMessage(); } }
0.0005 135568 2. test-> selecttest() E:ProgramDevelopmentRuntimeEnvironmentxampphtdocstesttest.php:86
0.0055 142528 3. PDOStatement->execute() E:ProgramDevelopmentRuntimeEnvironmentxampphtdocstesttest.php:57
Array ( [id] => 1 [a] => v [b] => w [c] => i )
Array ( [id] => 2 [a] => b [b] => l [c] => q )
Array ( [id] => 3 [a] => m [b] => p [c] => h )
Array ( [id] => 4 [a] => j [b] => i [c] => b )
Array ( [id] => 5 [a] => q [b] => g [c] => g )