dosrmo0442 2016-04-04 17:40
浏览 55

使用Android应用程序的post方法时,mysql是否足够转义字符串

I have an android app and it is connected to a php page with post method And I'm using mysqli_real_escape_string, as user can't see any error while logging in to my app in android,

Is escape string enough to prevent sql injection in my case ?

Am Using volley in android to post data

$email = $_POST['email'];
$email = mysqli_real_escape_string($con,$email);
  • 写回答

1条回答 默认 最新

  • douzhi1972 2016-04-04 17:49
    关注

    It depends on whether the variable is inside a string or not, if it is then you're fairly safe but there should be no reason just to implement prepared statements instead. Read more about it here: http://php.net/manual/en/mysqli.prepare.php

    Example below is from that site.

    <?php
    $mysqli = new mysqli("localhost", "my_user", "my_password", "world");
    
    /* check connection */
    if (mysqli_connect_errno()) {
        printf("Connect failed: %s
    ", mysqli_connect_error());
        exit();
    }
    
    $city = "Amersfoort";
    
    /* create a prepared statement */
    if ($stmt = $mysqli->prepare("SELECT District FROM City WHERE Name=?")) {
    
        /* bind parameters for markers */
        $stmt->bind_param("s", $city);
    
        /* execute query */
        $stmt->execute();
    
        /* bind result variables */
        $stmt->bind_result($district);
    
        /* fetch value */
        $stmt->fetch();
    
        printf("%s is in district %s
    ", $city, $district);
    
        /* close statement */
        $stmt->close();
    }
    
    /* close connection */
    $mysqli->close();
    ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?