当复制到虚拟主机帐户时,MySQL_REAL_ESCAPE_STRING方法在php中不起作用?

时间:2014-05-23 05:20:24

标签: php mysqli

以下php代码在本地计算机(WAMP服务器)上运行时工作正常。但是,当我将我的代码复制到我的网络服务器时,我收到一条警告信息

  

警告:mysql_real_escape_string():拒绝用户访问   '马歇尔' @'本地主机' (使用密码:NO)in   /home2/marshell/public_html/livedeals.uni.me/php/logmein.php

问题在于mysql_real_escape_string()方法。当我忽略该方法时,它在网络托管帐户上工作正常吗?有什么问题为什么它在我的本地wamp服务器上工作正常而不是我的实际网络托管帐户?

 <?php

    header("Access-Control-Allow-Origin: *");

    $FullNameBusinessName_original = $_POST['fnameorbname'];

    $con = mysqli_connect("localhost", "xyzusername", "xyzpassword", "xyzdatabasename", "3306");
    mysqli_select_db($con,"xyzdatabasename");

    $FullNameBusinessName=mysql_real_escape_string($FullNameBusinessName_original);

    mysqli_query($con,"INSERT INTO registration (FullNameBusinessName) VALUES ('".trim($FullNameBusinessName)."') ");

    mysqli_close($con);

    ?>

2 个答案:

答案 0 :(得分:1)

您可能希望使用mysqli_real_escape_string而不是mysql_real_escape_string,因为您使用的是mysqli功能。

$FullNameBusinessName = mysqli_real_escape_string($con, $FullNameBusinessName_original);

See documentation here for further information

答案 1 :(得分:0)

您使用的是mysqli_*,而不是mysql_*。尝试替换

$FullNameBusinessName = mysql_real_escape_string($FullNameBusinessName_original);

$FullNameBusinessName = mysqli_real_escape_string($con,$FullNameBusinessName_original);

对于doc: - http://de2.php.net/manual/en/mysqli.real-escape-string.php