看,我有一个连接到 mysql 数据库的类,但我有另一个文件,其中包含用户名、主机、密码和表名,如果我不包含并编写它们,它工作正常,但问题开始于我包括它,它返回我“未定义的变量”。谢谢,这是我的课:
<?php
include '../config/conexiongeneral.php';
class DbConnector {
var $theQuery;
var $link;
public function DbConnector(){
$host = $elnombredelhost;
$db = $labasededatos;
$user = $elnombredelusuario;
$pass = $lacontasena;
$this->link = mysql_connect($host, $user, $pass);
mysql_select_db($db);
register_shutdown_function(array(&$this, 'close'));
}
function query($query) {
$this->theQuery = $query;
return mysql_query($query, $this->link);
}
function fetchArray($result) {
return mysql_fetch_array($result);
}
function close() {
mysql_close($this->link);
}
}
?>
好吧,我忘记了我用以下方法调用这个函数:
<?php
include 'dbConnector.php';
$connector = new DbConnector();
$username = trim(strtolower($_POST['username']));
$username = mysql_real_escape_string($username);
$query = "SELECT usuario FROM $latablatres WHERE usuario = '$username' LIMIT 1";
$result = $connector->query($query);
$num = mysql_num_rows($result);
echo $num;
mysql_close();
?>