1. Johnny Harris
  2. as SQLite DB Server
  3. Sonntag, Januar 01 2017, 03:30 PM
  4.  Abonnieren via E-Mail
When I query a table that contains two records with VServer: 6.6.9, PHP7.0 and VSqlite PDO only one record is returned.

Is there an issue in my script or is there a bug in VSqite PDO?


$db = new PDO("vsqlite:host=127.0.0.1;dbname=test.db;port=15532;", "testuser", "*********");
$sql = "SELECT road_name, road_type FROM roads";
$ps = $db->prepare($sql);
try{
$ps->execute();
$rs = $ps->fetchAll(PDO::FETCH_ASSOC);
echo "Row Count: " . $ps->rowCount() . "<br>";
if($ps->rowCount() > 0){
echo "JSON Results = " . json_encode($rs);
} else {
echo 'No Records Found.';
}
$ps->closeCursor();
}catch(PDOException $e){
echo $e->getMessage();
}


PHP output from the above script:


Row Count: 2
JSON Results = [{"road_name":"Dave's Road","road_type":"County"}]
Kommentar
There are no comments made yet.
Sergey Pashkov Akzeptierte Antwort
0
Votes
Undo
Hello Johnny,

Yes, the source of the problem is in the VSqlite PDO and PHP PDO itself.

1) VSqlite PDO sets the current position to the first record, for internal operation
2) PDO fetchAll method doesn't set the position to the first record, but always uses fetch with FETCH_ORI_NEXT parameter, so the current record (and all records before it) is always missing.

We'll fix it in VSqlite PDO.

Temporary workaround can be something like that:
$rs = [];
$row = $ps->fetch( PDO::FETCH_ASSOC, PDO::FETCH_ORI_FIRST );
while( $row )
{
array_push( $rs, $row );
$row = $ps->fetch( PDO::FETCH_ASSOC, PDO::FETCH_ORI_NEXT );
}
Kommentar
There are no comments made yet.
Johnny Harris Akzeptierte Antwort
0
Votes
Undo
Thanks Sergey.
Kommentar
There are no comments made yet.
  • Seite :
  • 1


There are no replies made for this post yet.
However, you are not allowed to reply to this post.

Categories

Announcements & News
  1. 0 subcategories
Valentina Studio
  1. 2 subcategories
Valentina Server
  1. 4 subcategories
Valentina Database ADK
  1. 0 subcategories
Valentina Reports ADK
  1. 0 subcategories
Other Discussions
  1. 0 subcategories
BETA Testing
  1. 0 subcategories
Education & Research
  1. 0 subcategories
Omegabundle
  1. 0 subcategories