I'm trying to convert these PDO style statements into mysqli and I've done a lot of the other code but I'm stuck at this point.
It's working in the PDO script, but I'm unsure of how to change these.
I know I can use mysqli_query to execute plainly, but because I'm using bound parameters in these ($values and $values2) I'm not sure the proper way to do that. I realize I may can get away with removing my prepare statements but how can I execute queries with the $values and $values2 parameters?
I'm simply trying to preform a speed comparison between this and PDO so I don't need to have discussions about which is better or why I shouldn't convert these to mysqli, I just don't know exactly how to go about it
$insert = $MysqlConn->prepare($insertPlacement);
$insert = $MysqlConn->prepare($insertPlacement);
$update = $MysqlConn->prepare($updatePlacement);
//Array will contain records that are expired
$checkExisting = $MysqlConn->prepare($expiredCheck);
$existingRslt = $checkExisting->execute($values2);
$count3 = mysqli_fetch_assoc($checkExisting);
//Array will contain records that are valid
$checkExistingValid = $MysqlConn->prepare($validCheck);
$existingVldRslt = $checkExistingValid->execute($values2);
$count4 = mysqli_fetch_assoc($checkExistingValid);
// IF records do not exist, or records exist and today is after expiration date
if(empty($count3) && empty($count4)){
print_r("Inserting");
for($i=0; $i<$row2["QUANTITY"]; $i++) {
$insertRslt = $insert->execute($values);
}
}elseif(!empty($count3)){
print_r("Inserting");
for($i=0; $i<$row2['QUANTITY']; $i++){
$insertRslt = $insert->execute($values);
}
}elseif(!empty($count4)){
print_r("updatin");
for($i=0; $i<$row2['QUANTITY']; $i++){
$updateRslt = $update->execute($values);
First of all, there is no significant speed difference between mysqli and PDO. The time it takes the MySQL server to execute the query is much more important than any slight difference between one client API versus another. The choice of client API does not affect the execution time on the server.
Mysqli does not accept arguments to the mysqli_stmt::execute() method. You have to bind variables one by one using mysqli_stmt::bind_param(). This is not as convenient as using PDO, so I prefer to use PDO.
$checkExisting = $MysqlConn->prepare($expiredCheck);
$checkExisting->bind_param('s', $value2);
$existingRslt = $checkExisting->execute();
$result = $existingRslt->get_result();
$count3 = $result->fetch_assoc();