doujiao6116 2016-08-30 17:57
浏览 67
已采纳

php mysql_real_escape_string转换为mysqli [复制]

This question already has an answer here:

Hi im currently learning php and mysql a tutorial i am following uses the now out of date mysql_real_escape_string ive read the manual on mysqli's version of it but just cant really figure out how i would do something like the code below.

$username = mysql_real_escape_string($POST['username']);

any help in converting this over to mysqli and any tips are greatly apreciated

</div>
  • 写回答

3条回答 默认 最新

  • dongwen1935 2016-08-30 18:01
    关注

    I think you want this

    <?php
    $con=mysqli_connect("localhost","my_user","my_password","my_db");
    
    // Check connection
    if (mysqli_connect_errno()) {
     echo "Failed to connect to MySQL: " . mysqli_connect_error();
    }
    
    // escape variables for security
    $username = mysqli_real_escape_string($con, $_POST['username']);
    mysqli_close($con);
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?