mysql_real_escape_string 在 localhost 中完美运行,而不是在线运行
mysql_real_escape_string working perfectly in localhost, not working online
在页面 http://www.immocorbati.be/tehuur.php 上,过滤器功能无法正常工作。只有 "Prijsklasse"(价格)有效。但是,如果您过滤 "Gemeente"(区域)Boom,例如,它应该 return 1 家,但它说 none 被发现。与 "Type" studio 应该 return 3 但不 return 任何东西和 "Slaapkamer" (卧室)3 slaapkamers 应该 return 1 家一样,但同样 none 显示。
我不明白的是为什么它在localhost上完美运行,在线一半一半,因为那意味着功能达到了。这是文件。也许有人对为什么会发生这种情况有一些指示?是否可能与数据库相关?但是后端等所有其他功能都可以正常工作。
class Pand
{
//DB settings - Don't worry these are correct
private $m_sHost = "??????";
private $m_sUser = "????????";
private $m_sPassword = "??????";
private $m_sDatabase = "????????";
public function GetToonPandenHuurFilter()
{
//de panden worden op pagina getoond volgens filter
if ($link = mysqli_connect($this->m_sHost, $this->m_sUser, $this->m_sPassword, $this->m_sDatabase))
{
$b = $_POST['typewoning'];
$p = $_POST['plaats'];
$s = $_POST['slaapkamers'];
$k = $_POST['prijsklasse'];
$sSql = "select * from tblpand WHERE PandVerkoopstype='Te huur' AND PandOnline='Ja'";
if ($b !== 'all') {
$sSql .= " AND PandBebouwing='" . mysql_real_escape_string($b) . "'";
}
if ($p !== 'all') {
$sSql .= " AND PandPostcodeGemeente='" . mysql_real_escape_string($p) . "'";
}
if ($s !== 'all') {
$sSql .= "AND PandSlaapkamers='" . mysql_real_escape_string($s) . "'";
}
if ($k == '0') {
$sSql .= "";
}
if ($k == '1') {
$sSql .= "AND PandPrijs <'" . 301 . "'";
}
if ($k == '2') {
$sSql .= "AND PandPrijs <'" . 501 . "'";
}
if ($k == '3') {
$sSql .= "AND PandPrijs <'" . 701 . "'";
}
if ($k == '4') {
$sSql .= "AND PandPrijs <'" . 701 . "'";
}
$rResult = mysqli_query($link, $sSql);
return $rResult;
}
else
{
// er kon geen connectie gelegd worden met de databank
throw new Exception('Ooh my, something terrible happened to the database connection');
}
mysqli_close($link);
}
}
我添加了错误报告,反馈说:
mysql_real_escape_string(): Access denied for user ''@'10.246.64.177'
(using password: NO) in /customers/e/a/b/immocorbati.be/httpd.www/classes/Pand.class.php on line 1086
第 1086 行是:
$sSql .= " AND PandBebouwing='" . mysql_real_escape_string($b) . "'";
mysql_real_escape_string
需要数据库连接才能完成其工作。 mysql_real_escape_string
属于mysqlAPI。您正在使用 mysqli 建立连接。 mysql 和 mysqli 是两个完全不同的数据库 APIs; mysqli 连接对 mysql_* 没有用。 mysql 有在需要时隐式(尝试)建立连接的坏习惯。在您的本地主机上,它试图建立的隐式连接恰好有效(默认用户名,无密码等)。在您的主机上,它没有。
在使用 mysqli 时不要使用 mysql_real_escape_string
。使用 mysqli's parameter binding API or at the very least mysqli_real_escape_string
.
在页面 http://www.immocorbati.be/tehuur.php 上,过滤器功能无法正常工作。只有 "Prijsklasse"(价格)有效。但是,如果您过滤 "Gemeente"(区域)Boom,例如,它应该 return 1 家,但它说 none 被发现。与 "Type" studio 应该 return 3 但不 return 任何东西和 "Slaapkamer" (卧室)3 slaapkamers 应该 return 1 家一样,但同样 none 显示。
我不明白的是为什么它在localhost上完美运行,在线一半一半,因为那意味着功能达到了。这是文件。也许有人对为什么会发生这种情况有一些指示?是否可能与数据库相关?但是后端等所有其他功能都可以正常工作。
class Pand
{
//DB settings - Don't worry these are correct
private $m_sHost = "??????";
private $m_sUser = "????????";
private $m_sPassword = "??????";
private $m_sDatabase = "????????";
public function GetToonPandenHuurFilter()
{
//de panden worden op pagina getoond volgens filter
if ($link = mysqli_connect($this->m_sHost, $this->m_sUser, $this->m_sPassword, $this->m_sDatabase))
{
$b = $_POST['typewoning'];
$p = $_POST['plaats'];
$s = $_POST['slaapkamers'];
$k = $_POST['prijsklasse'];
$sSql = "select * from tblpand WHERE PandVerkoopstype='Te huur' AND PandOnline='Ja'";
if ($b !== 'all') {
$sSql .= " AND PandBebouwing='" . mysql_real_escape_string($b) . "'";
}
if ($p !== 'all') {
$sSql .= " AND PandPostcodeGemeente='" . mysql_real_escape_string($p) . "'";
}
if ($s !== 'all') {
$sSql .= "AND PandSlaapkamers='" . mysql_real_escape_string($s) . "'";
}
if ($k == '0') {
$sSql .= "";
}
if ($k == '1') {
$sSql .= "AND PandPrijs <'" . 301 . "'";
}
if ($k == '2') {
$sSql .= "AND PandPrijs <'" . 501 . "'";
}
if ($k == '3') {
$sSql .= "AND PandPrijs <'" . 701 . "'";
}
if ($k == '4') {
$sSql .= "AND PandPrijs <'" . 701 . "'";
}
$rResult = mysqli_query($link, $sSql);
return $rResult;
}
else
{
// er kon geen connectie gelegd worden met de databank
throw new Exception('Ooh my, something terrible happened to the database connection');
}
mysqli_close($link);
}
}
我添加了错误报告,反馈说:
mysql_real_escape_string(): Access denied for user ''@'10.246.64.177'
(using password: NO) in /customers/e/a/b/immocorbati.be/httpd.www/classes/Pand.class.php on line 1086
第 1086 行是:
$sSql .= " AND PandBebouwing='" . mysql_real_escape_string($b) . "'";
mysql_real_escape_string
需要数据库连接才能完成其工作。 mysql_real_escape_string
属于mysqlAPI。您正在使用 mysqli 建立连接。 mysql 和 mysqli 是两个完全不同的数据库 APIs; mysqli 连接对 mysql_* 没有用。 mysql 有在需要时隐式(尝试)建立连接的坏习惯。在您的本地主机上,它试图建立的隐式连接恰好有效(默认用户名,无密码等)。在您的主机上,它没有。
在使用 mysqli 时不要使用 mysql_real_escape_string
。使用 mysqli's parameter binding API or at the very least mysqli_real_escape_string
.