变量表和顺序没有设置,并且它没有在数组中推送字段。谁能在这里看到任何东西?
页
<?php
$table = new table;
$table->table = "db_firstaid";
$table->order = "aid_date";
$table->field("aid_id","false",NULL);
$table->field("aid_patient","true","[F]");
$table->field("aid_aider","true","[F]");
$table->field("aid_date","false","[F]");
$table->field("aid_time","false","[F]");
$table->table();
?>
类
<?php
class table{
/* Connect */
private $salt = '#######'
private $user = '#######'
private $pass = '#######'
private $host = '#######'
private $data = '#######'
private $db = '';
private $link = NULL;
private function connect(){
$this->link = mysql_connect($this->host, $this->user, $this->pass);
if(!$this->link){
die("<script type=\"text/javascript\">notyfy({text:'Error, could not connect to server.',type:'error',timeout:7000,});</script>");
}
$this->db = mysql_select_db($this->data,$this->link);
if(!$this->db){
die("<script type=\"text/javascript\">notyfy({text:'Error, could not connect to database.',type:'error',timeout:7000,});</script>");
}
}
private function disconnect(){
mysql_close($this->link);
}
/* Push fields into array */
private $fields = array();
public function field($f,$aes,$t){
return $this->fields[] = array($f,$aes,$t);
}
/* Compile SQL string */
public $table = '';
public $order = '';
private $sql = '';
private function genSQL(){
foreach($this->fields as $f){
if($f[1] == 'true'){
$this->sql = $this->sql . "AES_DECRYPT(".$f[0].",'[SALT]') AS ".$f[0].", ";
}else{
$this->sql = $this->sql . $f[0].", ";
}
}
$this->sql = substr($this->sql,0,-1);
$this->sql = "SELECT ".$this->sql." FROM ".$this->table." ORDER BY ".$this->order;
}
/* Query Database */
private $result = '';
private $number = '';
private function query(){
$this->genSQL();
$this->result = mysql_query($this->sql,$this->link) or die(mysql_error());
$this->number = mysql_num_rows($this->result);
}
/* Echo Table */
public function table(){
$this->connect();
$this->query();
if($this->number > 0){
while($row = mysql_fetch_array($this->result)){
echo "<tr class=\"selectable\">";
//Ignore this bit, yet to build.
echo "</tr>";
}
}
$this->disconnect();
}
}
答案 0 :(得分:2)
感谢您的建议。
我现在已经开始工作了,php失败了,类和函数被称为'table'所以我将函数重命名为'genTable'并将该类保留为'table',它现在正在运行。
答案 1 :(得分:0)
根据我的评论,尝试在需要的地方附加一些;
。即您在table
类的开头声明的接口变量。
正如 rid 所指出的那样,PHP可能会因解析错误而无声地失败。
如果您不知道,PHP中的所有语句都应附加;
字符。
显然,这实际上可能不是您正在使用的代码。那些哈希值将是一个非常重要的安全漏洞。 ; - )
答案 2 :(得分:-3)
试试这个:
$db_table = "db_firstaid";
$order = "aid_date";
$table = new table($db_table, $order);
然后在你的课堂上,使用像这样的构造函数:
public $table = '';
public $order = '';
private $sql = '';
public function __constructor($table, $order){
$this->table = $table;
$this->order = $order;
}
基本上,您不是在类中的任何位置设置表和顺序值,而是尝试使用这些值。
更新:OP确实设置了值,所以这个答案只是做OP已经做的另一种方式。此外,根据评论,问题可能在其他地方,OP似乎需要做更多的调试。