GrumpyCrouton GrumpyCrouton - 3 years ago 117
PHP Question

SQLite3 Prepared Statements select duplicated results

I'm attempting to convert some old sqlite3 database code into sqlite3 prepared statements to improve security on my site. I was considering switching to mysql but as of right now I'd like to get this working first.

I can't see what I've done wrong here, but all of my results are doubled.

Here is my code:

$sql = $upc->prepare("SELECT `uid`, `model`, `biosmodel`, `upc`, `systemsku`, `brand`, `hardwareids`, `status`, `pendingHardware` FROM `builds` WHERE `uid`=:id");
$sql->bindValue(':id', $uid, SQLITE3_INTEGER);
$result = $sql->execute();
echo "<pre>".print_r($result->fetchArray(),true)."</pre>";

My result is an array that has all of my keys, but also duplicated entries that seem to just be regular array keys
with duplicated information, like so:

[0] => 7
[uid] => 7
[1] => HP 15-AY041WM
[model] => HP 15-AY041WM
[2] => HP Notebook
[biosmodel] => HP Notebook
[3] => 889899757697
[upc] => 889899757697
[4] => X0H86UA#ABA
[systemsku] => X0H86UA#ABA
[5] => HP
[brand] => HP
[6] => [42,43,36,44,5,6,45,38,46,41,41,33]
[hardwareids] => [42,43,36,44,5,6,45,38,46,41,41,33]
[7] => 0
[status] => 0
[8] =>
[pendingHardware] =>

I'm not really sure why this is happening, and obviously I don't want all this duplicated information as it is needless. How can I resolve this issue?

Answer Source

If you just use fetchArray() default it fetches a result row as an associative and numerically indexed array .

In order to fetch only associative array then pass SQLITE3_ASSOC

It would be



Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download