Oh man.. prepared statements again. Using prepared
statements for JSP was a pain in the ass and now PHP...?
PreparedStatements added a good 50+ lines to my code, and with
these other projects with almost 40 -50 fields, its gonna
triple. My chief gripe with JSP prepared statements was that
you had to specify the type of data to be set, (setINT, setString
etc) , and that meant that I had to run a whole series of try
catches just to make sure they set the right data type.
You got any links or references for prepared statements on
PHP? I need to find a way to implement them such that I'll be
able to set values while looping through my form fields.
Oh no, prepared statements in PHP came like a gift from heaven
when PHP 5 was introduced actually. To specify the data type, all
you have to do is to use either 's' for strings, 'i' for 'integer'
etc as described in the link below. Then concatenate them all
together and pass it as a string in the first parameter of
bind_param(), followed by the data variables each as a parameter on
its own, like "$db->bind_param('isis', $id, $name, $credits,
$description)". If a given parameter doesn't belong to the data
type specified, it will be auto type-casted to it. That means I
don't have to, say, intval() all those users' numerical inputs and
I can simply dump it to the function to handle the dirty
laundry.
Besides, there are performance advantages as well, if you are
using the same prepared statement frequently and simply passing in
different variables each time as compared to individual
queries.
http://sg.php.net/manual/en/function.mysqli-stmt-bind-param.php