doushao1948 2015-05-24 03:02
浏览 312
已采纳

我需要保留mysqli_query()和mysqli_close()吗?

Do I still need to use mysqli_query($connection, $results); and mysqli_close($connection); ?

$sql = $connection->prepare("INSERT INTO pawnshop ".
    "(Pawnshop_Name, Street, Barangay, City, DTI_Permit_No, Mayor_Permit_No, Firstname, Middlename, Lastname, Contact_Number, Email_Address, Password) ".
    "VALUES ".
    "(?,?,?,?,?,?,?,?,?,?,?,?)");
    $sql->bind_param("ssssiissssss", $pawnshopName, $street, $barangay, $city, $dtiPermitNo, $mayorPermitNo, $firstName, $lastName, $middleName, $contactNumber, $email, $password);
    $sql->execute();
    $results = $sql->get_results();   
    mysqli_query($connection, $results);// Do I still need this?
    mysqli_close($connection); //Do I still need this
  • 写回答

2条回答 默认 最新

  • duanchen7401 2015-05-24 03:41
    关注

    this much part of the code is enough for you to finish querying database.

    $sql = $connection->prepare("INSERT INTO pawnshop ".
        "(Pawnshop_Name, Street, Barangay, City, DTI_Permit_No, Mayor_Permit_No, Firstname, Middlename, Lastname, Contact_Number, Email_Address, Password) ".
        "VALUES ".
        "(?,?,?,?,?,?,?,?,?,?,?,?)");
        $sql->bind_param("ssssiissssss", $pawnshopName, $street, $barangay, $city, $dtiPermitNo, $mayorPermitNo, $firstName, $lastName, $middleName, $contactNumber, $email, $password);
        $sql->execute();
        $results = $sql->get_results(); 
    

    I see that you are mixing both OOP and Procedural Programming methods together by using mysqli_close($connection), it is not a good practice even though you can do it. Instead use method in $connection object like $connection->close();

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥50 安装华大九天aether
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证