3

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

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

1
  • The only reason I can think of would be the resources involved - why use a method/function that will create a variable/resource that you won't use? It'd also be more explicit about what your code is doing... Commented Jan 4, 2010 at 4:17

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.