得到如下代码:
<?php
require_once("../classes/pdo.class.php");
$db = new mysql();
$db->connect();
class votingpanel{
public function logintopanel($username, $password){
//Dane z logowania + token
$login = mysql_real_escape_string($username);
$password = mysql_real_escape_string($password);
$sql = $db->prepare("SELECT * FROM xxx WHERE username = '$login'");
$sql = $db->exec($sql);
if($sql == 1){
$password = sha1($password);
$sql = $db->prepare("SELECT * FROM xxx WHERE username = '$login'");
$sql = $db->exec($sql);
$row = $sql->fetch();
if($row['password'] == $password and $row['toplistadmin'] == 1){
$_SESSION['toplist_admin'] = 1;
$_SESSION['toplist_adminloged'] = 1;
}
else{
return false;
}
}
else{
return false;
}
}
}
?>
pdo 类看起来像:
<?php
require_once("../konfiguracja.php");
class mysql{
public function connect(){
try {
$conn = new PDO('mysql:host=xxx;dbname=xxx', 'xxx', 'xxx');
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch(PDOException $e) {
echo 'ERROR: ' . $e->getMessage();
}
}
}
?>
作为回报,我得到这样的错误:
Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: Access denied for user 'radiolev'@'localhost' (using password: NO) in /home/radiolev/public_html/top/toplist.class.php on line 10
Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: A link to the server could not be established in /home/radiolev/public_html/top/toplist.class.php on line 10
Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: Access denied for user 'radiolev'@'localhost' (using password: NO) in /home/radiolev/public_html/top/toplist.class.php on line 11
Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: A link to the server could not be established in /home/radiolev/public_html/top/toplist.class.php on line 11
Fatal error: Call to a member function prepare() on a non-object in /home/radiolev/public_html/top/toplist.class.php on line 13
我不明白为什么它会出现,因为 mysql 密码很好。用普通的 mysql_connect 尝试了它们,它工作但仍然不知道为什么它出现在 pdo 中;s