1

One of my controllers takes an id field as $id and I use it on a query. When I check the query string it passes the id as string value like this:

select `id`, `name` from `table` where `id` = '1'

If I pass the intval($id) to the query it still works as expected.

select `id`, `name` from `table` where `id` = 1

My question: Which one is the optimized query and best practice? Thanks.

1 Answer 1

2

First of all: (int) is faster than intval().
Link: wiki.phpbb.com/Best_Practices:PHP.

About quote numbers or not: In practice, unless you're running a Google-sized operation, such conversion overhead is going to be microscopically small.
Link: stackoverflow.com/questions/6781976

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.