What is the best way to do more than one sql query with prepared statement?

What is the best way to do more than one sql query with prepared statement?
0

#1

With prepared statement, what is the best way to do more than one query? Can I just continue with the next query inside the current query or must this be done outside any closing {}? Can i do the following?


$sql = "INSERT INTO posts (category_id, topic_id, post_creator, post_content, post_date) VALUES (?,?,?,?,?);";

		if (!mysqli_stmt_prepare($stmt, $sql)) {
				   echo 'SQL error';
				   
				} else {
				    mysqli_stmt_bind_param($stmt, "iisss", $cid, $tid, $creator, $reply_content, $date);
				    mysqli_stmt_execute($stmt);

				

				    $sql2 = "UPDATE categories
                             SET last_post_date = ?, last_user_posted = ?
                             WHERE id = ?
                             LIMIT ?
				             ";
or should it be this?

$sql = "INSERT INTO posts (category_id, topic_id, post_creator, post_content, post_date) VALUES (?,?,?,?,?);";

		if (!mysqli_stmt_prepare($stmt, $sql)) {
				   echo 'SQL error';
				   
				} else {
				    mysqli_stmt_bind_param($stmt, "iisss", $cid, $tid, $creator, $reply_content, $date);
				    mysqli_stmt_execute($stmt);
                         }
}
				

				    $sql2 = "UPDATE categories
                             SET last_post_date = ?, last_user_posted = ?
                             WHERE id = ?
                             LIMIT ?
				             ";


#2

It could be my eyes playing tricks on me, but I can see no diference in the code you posted at the top from the code you posted after “or should it be this?”.


#3

The bottom one has some closed braces


#4

Can you highlight the differences please?