duanmo6937 2018-03-09 17:19
浏览 45
已采纳

too long

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);
  • 写回答

1条回答 默认 最新

  • doukanwen4114 2018-03-09 17:29
    关注

    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();
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路