为什么我的页面输出是空白

luckyforme 2004-03-23 09:45:17
///index.php
<?
Include("SQL.php");
$sql = new SQL; //生成新的Sql对象
if($sql-> DriverRegister("MySQL")) //注册数据库驱动
{
$sql->Connect("localhost","root","123456");
$res=$sql->query("select * from user"); //返回查询记录集
$rowsnum = $sql->getRowsNum($res);
if($rowsnum > 0)
{
$rows = $sql->getRows($res);
foreach($rows as $row) //循环取出记录集内容
{
foreach($row as $field)
{
print $field;
}
}
}
$sql->Close();
}
?>
//SQL.php
<?
class SQL
{
var $Driver; //实际操作的数据库驱动子类
var $connection; //共用的数据库连接变量
function DriverRegister($d)
{
if($d!="")
{
$include_path = ini_get("include_path");
$DriverFile = $include_path."'\".$d.".php";
//驱动的存放路径必须在PHP.ini文件中设定的INCLUDE_PATH下
if( file_exists( $DriverFile)) //查找驱动是否存在
{
include($DriverFile);
$this->Driver = new $d();
// 根据驱动名称生成相应的数据库驱动类
return true;
}
}
return false; //注册驱动失败
}

function Connect($host,$user,$passwd,$database)//连接数据库的函数
{
$this->Driver->host=$host;
$this->Driver->user=$user;
$this->Driver->passwd=$passwd;
$this->Driver->database=$database;
$this->connection = $this->Driver->Connect();
}
function Close()//关闭数据库函数
{
$this->Driver->close($this->connection);
}
function Query($queryStr)//数据库字符串查询函数
{
return $this->Driver->query($queryStr,$this->connection);
}
function getRows($res)//查找行
{
return $this->Driver->getRows($res);
}
function getRowsNum($res)//取得行号
{
return $this->Driver-> getRowsNum ($res);
}
?>
//include_path下的MYSQL.php include_path=c:\php4\include
<?
Class MySQL
{
var $host;
var $user;
var $passwd;
var $database;
function MySQL() //利用构造函数实现变量初始化
{
$host = "";
$user = "";
$passwd = "";
$database = "";
}
function Connect()
{
$conn = MySQL_connect($this->host, $this->user,$this->passwd,$database) or die("Could not connect to $this->host");
MySQL_select_db($this->database,$conn) or
die("Could not switch to database $this->database;");
return $conn;
}
function Close($conn)
{
MySQL_close($conn);
}

function Query($queryStr, $conn)
{
$res =MySQL_query($queryStr, $conn) or
die("Could not query database");
return $res;
}
function getRows($res)
{
$rowno = 0;
$rowno = MySQL_num_rows($res);
if($rowno>0)
{
for($row=0;$row<$rowno;$row++)
{
$rows[$row]=MySQL_fetch_row($res);
}
return $rows;
}
}
function getRowsNum($res)
{
$rowno = 0;
$rowno = mysql_num_rows($res);
return $rowno;
}
}
?>
为什么运行index.php没有什么显示呢?请高手指教
...全文
131 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
ice_berg16 2004-03-24
  • 打赏
  • 举报
回复
sql->Connect("localhost","root","123456");
后面少个个参数,应该把数据库名称也写上
alder2008 2004-03-24
  • 打赏
  • 举报
回复
up
语法有问题才会这样的!
52juanjuan 2004-03-24
  • 打赏
  • 举报
回复
是你的调用参数不对引起的吧,同意楼上的说法,检查清楚点
xylegend 2004-03-24
  • 打赏
  • 举报
回复
能指出MySQL.php on line 17的代码吗?
$res=$sql->query("select * from user"); 你的这句赋值不妥,缺少连接数据库的参数
$sql->Connect("localhost","root","123456"); 和
function Connect($host,$user,$passwd,$database)//连接数据库的函数
的参数值也不匹配啊,$database是什么来的?
luckyforme 2004-03-24
  • 打赏
  • 举报
回复
up
luckyforme 2004-03-24
  • 打赏
  • 举报
回复
经过我一阵修改后还有错
Notice: Undefined variable: database in c:\php4\include\MySQL.php on line 17

Notice: Undefined property: in c:\php4\include\MySQL.php on line 17
Could not switch to database ;
请问这是什么意思
xylegend 2004-03-24
  • 打赏
  • 举报
回复
你的MySQL.php哪儿去了?
xylegend 2004-03-24
  • 打赏
  • 举报
回复
你的MySQL.php在哪儿去了?
mistjin 2004-03-24
  • 打赏
  • 举报
回复
以后代码不要贴这么长
关键来一点就行了
luckyforme 2004-03-24
  • 打赏
  • 举报
回复
问题自己解决了,谢谢大家了
luckyforme 2004-03-24
  • 打赏
  • 举报
回复
//index.php
<?
include("SQL.php");
$sql = new SQL; //生成新的Sql对象
if($sql-> DriverRegister("MySQL")) //注册数据库驱动
{
$sql->Connect("localhost","root","123456","");
$res=$sql->query("select * from user"); //返回查询记录集
$rowsnum = $sql->getRowsNum($res);
if($rowsnum > 0)
{
$rows = $sql->getRows($res);
foreach($rows as $row) //循环取出记录集内容
{
foreach($row as $field)
{
print $field;
}
}
}
$sql->Close();
}
?>
//SQL.php
<?
class SQL
{
var $Driver; //实际操作的数据库驱动子类
var $connection; //共用的数据库连接变量
function DriverRegister($d)
{
if($d!="")
{
$include_path = ini_get("include_path");
$DriverFile = $include_path."/".$d.".php";
//驱动的存放路径必须在PHP.ini文件中设定的INCLUDE_PATH下
if( file_exists( $DriverFile)) //查找驱动是否存在
{
include($DriverFile);
$this->Driver = new $d();
// 根据驱动名称生成相应的数据库驱动类
return true;
}
}
return false; //注册驱动失败
}

function Connect($host,$user,$passwd,$database)//连接数据库的函数
{
$this->Driver->host=$host;
$this->Driver->user=$user;
$this->Driver->passwd=$passwd;
$this->Driver->database=$database;
$this->connection = $this->Driver->Connect();
}
function Close()//关闭数据库函数
{
$this->Driver->close($this->connection);
}
function Query($queryStr)//数据库字符串查询函数
{
return $this->Driver->query($queryStr,$this->connection);
}
function getRows($res)//查找行
{
return $this->Driver->getRows($res);
}
function getRowsNum($res)//取得行号
{
return $this->Driver-> getRowsNum ($res);
}
}
?>
//MySQL.php
<?
Class MySQL
{
var $host;
var $user;
var $passwd;
var $database;
function MySQL() //利用构造函数实现变量初始化
{
$host = "";
$user = "";
$passwd = "";
$database = "";
}
function Connect()
{
$conn = mysql_connect($this->host, $this->user,$this->passwd,$this->$database) or die("Could not connect to $this->host");
mysql_select_db($this->database,$conn) or die("Could not switch to database $this->database;");
return $conn;
}
function Close($conn)
{
MySQL_close($conn);
}

function Query($queryStr, $conn)
{
$res =mysql_query($queryStr, $conn) or
die("Could not query database");
return $res;
}
function getRows($res)
{
$rowno = 0;
$rowno = MySQL_num_rows($res);
if($rowno>0)
{
for($row=0;$row<$rowno;$row++)
{
$rows[$row]=MySQL_fetch_row($res);
}
return $rows;
}
}
function getRowsNum($res)
{
$rowno = 0;
$rowno = mysql_num_rows($res);
return $rowno;
}
}
?>
这是我修改后的
xylegend(晓逸) 我的$res=$sql->query("select * from user"); 是有连接数据库啊(function Query($queryStr, $conn)
{
$res =mysql_query($queryStr, $conn) or
die("Could not query database");
return $res;
}),还是会出现像上面的两个提示为什么呢
ice_berg16 2004-03-23
  • 打赏
  • 举报
回复
因为你的页面有错误,
而php.ini里display_errors = off了

把它改成on然后再找错误吧

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧