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.

moonwalker
  • 1,157
  • 1
  • 18
  • 34

1 Answers1

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