php - What is the correct order of statement method calls using prepared statements? -
i want make db secure possible, , 1 of things i've learned use prepared statements...so that's i'm doing.
i need confirmation make sure order of execution ok.
does following make sense, or missing something?
$sql = 'select ...'; $conn = @ new mysqli($host, $user, $pwd, $db); $stmt = $conn->stmt_init(); // initialize prepared statement $stmt->prepare($sql); $stmt->bind_param('i', ...); $stmt->bind_result(..., ..., ...); $stmt->execute(); while ($stmt->fetch()) { ... } $stmt->free_result(); // free database resources other queries $stmt->close(); // close statement $conn->close(); //close database connection
i don't need call stmt_init()
-- @ least, doesn't seem necessary, according example on page of mysqli::prepare()
you might want check :
- if connection db has been established -- see examples on page of
mysqli::__construct()
, usingmysqli::connect_error
. - if statement has prepared -- checking return value of
mysqli::prepare()
before using it - if execution of prepared statement has been successful, testing return value of
mysqli_stmt::execute()
Comments
Post a Comment