2

I am using mysqli_stmt::bind_param function in my PHP scripts.

It is not convenient to care whether you pass parameter type 'd' or type 's' or whatever. Why it is bad to always use type 's' for strings, integers and doubles?

As far as I understand mysql will handle type conversion itself when needed.

j0k
  • 22,600
  • 28
  • 79
  • 90
Georgy Nemtsov
  • 786
  • 1
  • 8
  • 19

1 Answers1

2

The way you put it, it's indeed doesn't really matter. The only issue would be in case mysql is run in strict mode.

Nevertheless, as a matter of fact, a developer should be always aware of the type of the query part in general.
Because it could be not only string or number but also identifier or something else.
So, it's better to make placeholders type-hinted, to let driver apply proper formatting according to query part type, making query looks like this:

SELECT * FROM table WHERE field=?s AND id IN(?a) ORDER BY ?n LIMIT ?i 
Your Common Sense
  • 156,878
  • 40
  • 214
  • 345