简体   繁体   中英

if statement within mysqli::prepare

Is it posible to insert an if statement within a mysqli::prepare statement?

$check->$DBH->prepare('IF EXISTS(SELECT COUNT(ID) FROM users WHERE username=?)>0');
$check->bind_param('i',$username);
$check->execute();

If so, my next question is how to handle the query? Would it return 1 if found, or an affected row or a result.

$result=$check->affected_rows;//rows affected

Or

$check->bind_result($rowExists);//row exist

Or

$check->num_rows();//number of rows

Or is all he above possible?

Prepared statement is dealing with data only

It doesn't affect your SQL statement in any way.

Any working SQL statement with dynamical data literals substituted with placeholders would work

If you are passing illegal SQL into prepared statement, it won't work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM