我有此PHP代码来填充一个表的一些数据来的思想报分贝, 但是当我exec的它说PHP的MySQL查询致命错误
"Fatal error: Call to undefined method MysqlClass::query()"
<?php
include "config.php";
$data = new Mysqlclass();
$data->connetti();
$post_sql = $data->query("SELECT * FROM products ORDER BY id DESC");
if(mysql_num_rows($post_sql) > 0)
{while($post_obj = $Data->estrai($post_sql))
{$id=$post_obj->id;
$name = stripcslashes($post_obj->name);
$cat = stripcslashes($post_obj->category);
$price= stripcslashes($post_obj->price);
echo "<td>".$id."</td>";
echo "<td>".$name."</td>";
echo "<td>".$cat."</td>";
echo "<td>".$price."</td>";
}
}else{
echo"Tabella vuota";
}
$data->disconnetti();
?>
的错误是在2线时,我声明$Data->query
。
也许功能查询不正确,我是新的PHP脚本。
我已经在教程中使用了这段代码。我不知道“查询”和“estrai”(提取)键是否正确。
下面是配置文件:
<?php
class MysqlClass
{
private $nomehost = "localhost";
private $nomeuser = "root";
private $password = "xxxxx";
private $nomedb = "intse";
private $attiva = false;
public function connetti()
{
if(!$this->attiva)
{
if($connessione = mysql_connect($this->nomehost,$this->nomeuser,$this->password) or die (mysql_error()))
{
$selezione = mysql_select_db($this->nomedb,$connessione) or die (mysql_error());
}
} else{
return true;
}
}
public function disconnetti()
{
if($this->attiva)
{
if(mysql_close())
{
$this->attiva = false;
return true;
} else {
return false;
}
}
}
}
?>
http://imageshack.com/a/img35/1966/pd0v.png 所以现在我必须填写与DB 2日进入和ROW3与DB 3项2行,并增加HTML表格的行数,以填补其他数据库条目。 谢谢。
您与db的连接失败。你需要弄清楚为什么。 –
不知道没有看到类文件 – Steve
谢谢我会检查配置,也许mysql不接受我的连接 – andreyo