tags:

views:

69

answers:

1

I understand that sqlite_exec is for queries that does not return resultset and sqlite_query is for queries that return resultset.

However can I use sqlite_query for all kinds of queries just like how mysql_query and are there any sideeffects to this?

+1  A: 

sqlite_query

sqlite_query() returns a buffered, seekable result handle. This is useful for reasonably small queries where you need to be able to randomly access the rows. Buffered result handles will allocate memory to hold the entire result and will not return until it has been fetched. If you only need sequential access to the data, it is recommended that you use the much higher performance sqlite_unbuffered_query() instead.

sqlite_exec

This function will return a boolean result; TRUE for success or FALSE for failure. If you need to run a query that returns rows, see sqlite_query().

I don't think there will be that much difference between always using sqlite_query, although you may lose some clock cycles while sqlite_query is figuring out that there are no results. Both functions return FALSE on failure, so as long as you always check for FALSE rather than TRUE you might be able to get away with it.

You may also want to look at sqlite_unbuffered_query if you are doing straightforward PHP database work, sequentially iterating through results from the query.

I checked the C API for this and it doesn't give any indication of a performance penalty for using one function over the other.

taspeotis
ok that's awesome!
thephpdeveloper