After reading related questions about parameter-ized queries, I realize that they are the way to go to completely (well, unless you're interpolating table values or something) prevent SQL injection, even if they are somewhat (okay, very much) verbose and repetitive. However, I've been wondering how to properly test them for error handling, and also if error-handling in some cases is even necessary.
Sorry if this is a newbie question, but aren't PHP and MySQL installed on the same server anyways? Unless one is concerned with the syntax of the connection query or the database connection codes or whatever, I'm not entirely certain that it's necessary to check for errors with every statement like:
if ($stmt->bind_param('s',$logon)) {
if ($stmt->execute()) {
if ($stmt->bind_result()) {
} else { return 'bat'; }
} else { return 'bar'; }
} else { return 'foo'; }
// or else:
$stmt->bind_param('s',$logon)) or trigger_error('Could not bind parameters!',E_USER_ERROR);
// etc.
As a side note, if the $stmt
connection isn't closed for some reason, while the mysqli
connection is, does that cause some some sort of internal server error? Or does closing the actual mysqli
connection do the trick as well? Why should you close $stmt
in the first place?
Anyways, thanks for responding.
Update: MySQL Parameterized Queries - Cache Duration [duplicate] // closing $stmt isn't necessary as PHP will do it in the end anyway.
Notes: $stmt -> prepare(...)
interacts with the server.