使用引擎LiteDiary并在网站上搜索有问题:如果用户未登录并尝试搜索某些内容,则会突然出现此错误:
警告:mysql_real_escape_string():拒绝用户访问 'apache'@'localhost'(使用密码:NO)in /var/www/bmz/data/www/info.mobilux.info/sources/lib/drivers/mysql/mysql.php 第89行
警告:mysql_real_escape_string():无法链接到服务器 建立在 /var/www/bmz/data/www/info.mobilux.info/sources/lib/drivers/mysql/mysql.php 第89行
这里代码:
<?
class DB_Connection {
public $driver,$server,$user,$database,$prefix,$connection,$queries,$encoding,$log;
private $password;
function __construct(array $a,$enc=array('enc'=>'utf8','coll'=>'utf8_unicode_ci'),$l=false,$cache=true) {
$this->server=$a['server'];
$this->user=$a['user'];
$this->password=$a['pass'];
$this->name=$a['db'];
$this->prefix=$a['prefix'];
$this->queries=0;
$this->log=$l?array():false;
$this->cache=$cache;
$this->connected=false;
$this->encoding=$enc;
$this->set_enc=false;
$this->driver='mysql';
}
function init() {
if (!$this->connected) {
if ($this->connection=mysql_connect($this->server,$this->user,$this->password)) {
mysql_select_db($this->name,$this->connection);
$this->connected=true;
if (!$this->set_enc) $this->set_enc=self::q("SET NAMES '{$this->encoding['enc']}' COLLATE '{$this->encoding['coll']}'");
}
}
}
function q($q,$p=true) {
self::init();
$this->queries++;
if ($this->log!==false) $this->log[$this->queries]=$q;
if ($p) $q=str_replace('`_',"`{$this->prefix}_",$q);
if ($this->cache&&(strpos($q,'UPDATE')!==false||strpos($q,'INSERT')!==false||strpos($q,'DELETE')!==false)) self::cache_clean();
return mysql_query($q,$this->connection);
}
function qncl($q,$p=true) {
self::init();
$this->queries++;
if ($this->log!==false) $this->log[$this->queries]=$q;
if ($p) $q=str_replace('`_',"`{$this->prefix}_",$q);
return mysql_query($q,$this->connection);
}
function qm($q,$r=false) {
foreach ($q as $k=>$i) if (!self::q($i)) {$r[]=array('no'=>mysql_errno(),'text'=>mysql_error());}
return $r;
}
function query($query,$one=false,$cache=true) {
if ($this->cache&&$cache&&file_exists(CACHE.'sql/'.md5($query))) {
$b=unserialize(file_get_contents(CACHE.'sql/'.md5($query)));
} else {
$q=self::q($query);
if ($q) {
if (!$one) {
for ($b=array();@$c=mysql_fetch_assoc($q);$b[]=$c);
} else {
$b=mysql_fetch_assoc($q);
}
if ($this->cache&&$cache) self::cache_query($query,$b);
} else {
return false;
}
}
if ($b) return $b;
}
function qq($q) {
return @mysql_result(self::q($q),0,0);
}
function last_id() {
return mysql_insert_id();
}
function cache_query($q,$r) {
if ($f=fopen(SRC.'cache/sql/'.md5($q),'ab')) {
fwrite($f,serialize($r));
fclose($f);
} else {echo 'Cannot open file for caching';}
}
function cache_clean() {
if (opendir($d=CACHE.'sql')) {
while ($f=readdir()) {
if ($f!='.'&&$f!='..'&&is_file($n=$d.'/'.$f)) {
unlink($n);
}
}
closedir();
}
}
function esc($a) {
return mysql_real_escape_string($a);
}
}?>
我希望这是一个简单的问题,有人帮助我。谢谢!
答案 0 :(得分:0)
有人可能想知道为什么需要登录才能使用此功能。 Here is the answer
编辑:您的解决方案可能涉及连接到mysql数据库,但不执行任何类型的用户凭据检查,以便msyql连接处于活动状态,但用户不需要&#39;登录&#39;本身。