Introduction to SQLite |
|
2024-11-25 |
|
|
13 |
|
|
Plain sqlite_fetch_array() is quite inefficient since both numeric and string keys
are created and don't even use them.
<?php
function check_if_exists($cc)
{
$result = safe_query("SELECT id FROM country_data WHERE cc_code_2='{$cc}'");
return sqlite_fetch_array($result, SQLITE_NUM) ? TRUE : FALSE;
}
?>
By specifying SQLITE_NUM or SQLITE_ASSOC we can tell SQLite what keys should be used
in the result array. Since creation of numeric keys is faster then string keys, in our particular
case it is better to use SQLITE_NUM.
FYI
SQLite's sqlite_fetch_array() is actually faster then equivalent functions in other database extensions
since the data is not stored twice. SQLite does a copy on write duplicate, which means that unless the result
is modified only one instance is stored and the only overhead of using both numeric & string keys is the key
creation process.