Though it's not entirely clear what your actual question is, let me say this:
The first snippet you posted is right out. There is not a single valid argument for you to use a deprecated extension (or an extension that is being deprecated) like mysql_*
at all. Forget about all those pesky mysql_connect
calls all together.
looking at the other two snippets I'm guessing you're using PDO
, which does support prepare-emulation. In fact, it emulates prepares by default. If, however the third snippet is a mysqli_*
snippet, what's the problem? unless you're running MySQL 3.x you're all right there.
The difference between emulated prepares and direct prepare calls is that emulation might spot some syntax errors without the MySQL server being involved, thus being more efficient. If the your MySQL server doesn't support prepared statements, however, I'm pretty sure PDO
takes care of that for you, so you should be all right there. Don't know about mysqli_*
, though.
All things considered, I'm in favour of the second snippet anyhow. It's less code, does the same thing as the third snippet and allows for tidy, easy to maintain code.
On the question of "What type of parameters can be used in method execute", You can consult the doc pages, in case of PDO
it's either no params, or an array as you can see here: bool PDOStatement::execute ([ array $input_parameters ] )
In case of mysqli_execute
, it depends on your using the OO or procedural style, as shown in the docs:
bool mysqli_stmt::execute ( void )
for OO
bool mysqli_stmt_execute ( mysqli_stmt $stmt )
for procedural style