我有两个不同的表供学生和老师使用(因为两者都有不同的字段),主键ID和所有页面都正确打开但我读到这是一个很好的做法,有两个不同的登录表单,所以我创建了一个用户表使用主键user_id为教师和学生提供一些共同的字段。 user_id是学生表和教师表的外键。所有pages.inc文件都包含在所有页面上。当我在user.class.php文件中提供id时,如$ id = 15;脚本工作正常,否则会在所有页面上显示错误。有人可以帮忙吗?
( ! ) SCREAM: Error suppression ignored for
( ! ) Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given
in C:\wamp\www\curri\web\classes\db.class.php on line 44
Call Stack
# Time Memory Function Location
1 0.0008 251456 {main}( ) ..\dashboard.php:0
2 0.0055 257088 require_once( 'C:\wamp\www\curri\web\global.inc.php' )
..\dashboard.php:1
3 1.0224 378496 usertools->get( ) ..\global.inc.php:20
4 1.0224 379224 DB->select( ) ..\usertools.class.php:56
5 1.0229 379704 mysql_num_rows ( ) ..\db.class.php:44
( ! ) SCREAM: Error suppression ignored for
( ! ) Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given
in C:\wamp\www\curri\web\classes\db.class.php on line 26
Call Stack
# Time Memory Function Location
1 0.0008 251456 {main}( ) ..\dashboard.php:0
2 0.0055 257088 require_once( 'C:\wamp\www\curri\web\global.inc.php' )
..\dashboard.php:1
3 1.0224 378496 usertools->get( ) ..\global.inc.php:20
4 1.0224 379224 DB->select( ) ..\usertools.class.php:56
5 1.0232 379656 DB->processRowSet( ) ..\db.class.php:47
6 1.0232 379912 mysql_fetch_assoc ( ) ..\db.class.php:26
这些文件包含在所有页面上。
global.inc.php ----
<?php
require_once ("classes/user.class.php");
require_once ("classes/usertools.class.php");
require_once ("classes/db.class.php");
$db = new DB();
$db->connect();
$usertools = new usertools();
session_start();
if(isset($_SESSION['logged_in'])) {
$user = unserialize($_SESSION['user']);
$_SESSION['user'] = serialize($usertools->get($user->id));
}
?>
usertools.class.php -----
<?php
require_once ("user.class.php");
require_once ("db.class.php");
class usertools {
public function login($username, $password, $usertype)
{
global $table;
$result = mysql_query("SELECT * FROM $table WHERE user_name='$username'
&& password='$password' && user_type='$usertype'");
if(mysql_num_rows($result) > 0)
{
$_SESSION["user"] = serialize(new User(mysql_fetch_assoc($result)));
$_SESSION["login_time"] = time();
$_SESSION["logged_in"] = 1;
return true;
}else{
return false;
}
}
//returns a User object. Takes the users id as an input
public function get($id)
{
$db = new DB();
$result = $db->select('user', "user_id = $id");
return new User($result);
}
}
?>
user.class.php ---
<?php
require_once ("db.class.php");
class User {
public $id;
.
.
public $usertype;
function __construct($data) {
$this->id = (isset($data['id'])) ? $data['id'] : "";
.
.
$this->usertype = (isset($data['user_type'])) ? $data['user_type'] : "";
}
public function saveteacher($isNewUser = false) {
global $table;
$db = new DB();
$data = array(
"user_name" => "'$this->username'",
"email" => "'$this->email'",
.
.
.
"user_type" => "'$this->usertype'" );
$this->id = $db->insert($data, 'user');
$data1 = array(
"user_id" => "'$this->id'",
"teacher_id" => "'$this->teacher_id'",
.
.
"subject" => "'$this->subject'",
);
$db->insert($data1, 'teachers');
}
return true;
}
public function savestudent($isNewUser = false) {
}
}
?>
db.class.php ---
<?php
class DB {
protected $db_host = "localhost";
protected $db_user = "root";
protected $db_password = "";
protected $db_name = "db_name";
public $table;
public function connect() {
$conn= mysql_connect($this->db_host, $this->db_user, $this->db_password);
mysql_select_db($this->db_name);
return true;
}
public function processRowSet($rowSet, $singleRow=false)
{
$resultArray = array();
while($row = mysql_fetch_assoc($rowSet))
{
array_push($resultArray, $row);
}
if($singleRow === true)
return $resultArray[0];
return $resultArray;
}
public function select($table, $where) {
$sql = "SELECT * FROM $table WHERE $where";
$result = mysql_query($sql);
if(mysql_num_rows($result) == 1)
return $this->processRowSet($result, true);
return $this->processRowSet($result);
}
}
?>
答案 0 :(得分:1)
您似乎正在使用尖叫扩展。
从手册:
尖叫扩展可以禁用静音 错误控制操作符,以便报告所有错误。此功能 由ini设置控制。
Scream是调试的扩展,旨在显示尽可能多的错误消息。这是通过忽略@运算符并始终具有最高的error_reporating级别来完成的。 (无论您的error_reporting设置如何)。因此,您必须在php.ini中停用扩展名:
scream.enabled = off
BTW:我不会更新有170个代码错误的网站的服务器。现在这是一颗定时炸弹。最好将它们逐站点迁移到新的PHP版本。也许在迁移过程中有两台服务器并行。