我做错了什么?如果主键不连续,如何跟踪db游标?
MySQL驱动程序。
$sql = "SELECT * FROM employees";
$stmt = $db->query($sql);
$result = $stmt->fetch(PDO::FETCH_LAZY);
var_dump($result);
output: object(PDORow)[3] public 'queryString' => string 'SELECT * FROM employees' (length=23) public 'employeeNumber' => string '1002' (length=4) public 'lastName' => string 'Murphy' (length=6) public 'firstName' => string 'Diane' (length=5) public 'extension' => string 'x5800' (length=5) public 'email' => string 'dmurphy@classicmodelcars.com' (length=28) public 'officeCode' => string '1' (length=1) public 'reportsTo' => null public 'jobTitle' => string 'President' (length=9)
$result = $stmt->fetch(PDO::FETCH_ORI_FIRST);
var_dump($result);
output: array (size=8) 'employeeNumber' => string '1056' (length=4) 'lastName' => string 'Patterson' (length=9) 'firstName' => string 'Mary' (length=4) 'extension' => string 'x4611' (length=5) 'email' => string 'mpatterso@classicmodelcars.com' (length=30) 'officeCode' => string '1' (length=1) 'reportsTo' => string '1002' (length=4) 'jobTitle' => string 'VP Sales' (length=8)
$result = $stmt->fetch(PDO::FETCH_ORI_NEXT);
var_dump($result);
output: array (size=16) 'employeeNumber' => string '1076' (length=4) 0 => string '1076' (length=4) 'lastName' => string 'Firrelli' (length=8) 1 => string 'Firrelli' (length=8) 'firstName' => string 'Jeff' (length=4) 2 => string 'Jeff' (length=4) 'extension' => string 'x9273' (length=5) 3 => string 'x9273' (length=5) 'email' => string 'jfirrelli@classicmodelcars.com' (length=30) 4 => string 'jfirrelli@classicmodelcars.com' (length=30) 'officeCode' => string '1' (length=1) 5 => string '1' (length=1) 'reportsTo' => string '1002' (length=4) 6 => string '1002' (length=4) 'jobTitle' => string 'VP Marketing' (length=12) 7 => string 'VP Marketing' (length=12)
$result = $stmt->fetch(PDO::FETCH_ORI_LAST);
var_dump($result);
output: array (size=8) 0 => string '1088' (length=4) 1 => string 'Patterson' (length=9) 2 => string 'William' (length=7) 3 => string 'x4871' (length=5) 4 => string 'wpatterson@classicmodelcars.com' (length=31) 5 => string '6' (length=1) 6 => string '1056' (length=4) 7 => string 'Sales Manager (APAC)' (length=20)