SQLite3Result::fetchArray by default uses the SQLITE3_BOTH mode, which returns a 0-indexed and associative array of the selected columns.
Meaning you will receive a value like:
$lastrow = array(
0 => '19',
'id' => '19'
);
To resolve the issue you simply need to change fetchArray to retrieve a single value using either SQLITE3_NUM or SQLITE3_ASSOC.
$row = $db->query('select id from users');
while ($lastrow = $row->fetchArray(SQLITE3_NUM)) {
$id = implode($lastrow);
//list($id) = $lastrow; //alternative to implode
}
$database = 'E:/database/users/'.$id.'/';
Alternatively you only need to specify the column name to retrieve, instead of using implode.
$row = $db->query('select id from users');
while ($lastrow = $row->fetchArray()) {
$id = $lastrow['id'];
}
$database = 'E:/database/users/'.$id.'/';
Since it appears you only need the last row, I recommend changing your query to improve overall performance.
SELECT MAX(id) FROM users
or
SELECT id FROM users ORDER BY id DESC LIMIT 1
Allowing you to retrieve the last id without iterating over the entire users table.
if ($row = $db->query('SELECT MAX(id) FROM users')) {
if ($row->numColumns()) {
list($id) = $row->fetchArray(SQLITE3_NUM);
$database = 'E:/database/users/'.$id.'/';
}
}