第24章 应用smarty模板开发电子商务
发表在PHP图书答疑
2014-07-24
是否精华
是
否
版块置顶:
是
否
设置时间:
非永久
永久
起始时间:
结束时间:
是否扣分:
是
否
打开127.0.0.1/24/时错误提示:Error!: SQLSTATE[28000] [1045] Access denied for user 'root'@'localhost' (using password: YES)
精彩评论 21
2014-07-25
11L
读者您好:
测试没有发现你说的这个提示信息,请问你访问的是哪个页面,做什么操作出现的?
Warning: Cannot modify header information - headers already sent by (output started at C:\AppServ\www\24\system\system.class.inc.php:1) in C:\AppServ\www\24\public.php on line 2
该提示是由于类似header('Content-Type:text/html;charset= UTF-8');这句代码,在发送头之前不能有任何输出,需要检查什么地方有输出。
测试没有发现你说的这个提示信息,请问你访问的是哪个页面,做什么操作出现的?
Warning: Cannot modify header information - headers already sent by (output started at C:\AppServ\www\24\system\system.class.inc.php:1) in C:\AppServ\www\24\public.php on line 2
该提示是由于类似header('Content-Type:text/html;charset= UTF-8');这句代码,在发送头之前不能有任何输出,需要检查什么地方有输出。
2014-07-26
12L
我修改了system.class.inc.php文件,<?php
//数据库连接类
class ConnDB{
var $dbtype;
var $host;
var $user;
var $pwd;
var $dbname;
//构造方法
function ConnDB($dbtype,$host,$user,$pwd,$dbname){
$this->dbtype=$dbtype;
$this->host=$host;
$this->user=$user;
$this->pwd=$pwd;
$this->dbname=$dbname;
}
//实现数据库的连接并返回连接对象
function GetConnId(){
if($this->dbtype=="mysql" || $this->dbtype=="mssql"){
$dsn="$this->dbtype:host=$this->host;dbname=$this->dbname";
}else{
$dsn="$this->dbtype:dbname=$this->dbname";
}
try {
$conn = new PDO($dsn, $this->user, $this->pwd); //初始化一个PDO对象,就是创建了数据库连接对象$pdo
$conn->query("set names utf8");
return $conn;
} catch (PDOException $e) {
die ("Error!: " . $e->getMessage() . "<br/>");
}
}
}
//数据库管理类
class AdminDB{
function ExecSQL($sqlstr,$conn){
$sqltype=strtolower(substr(trim($sqlstr),0,6));
$rs=$conn->prepare($sqlstr); //准备查询语句
$rs->execute(); //执行查询语句,并返回结果集
if($sqltype=="select"){
$array=$rs->fetchAll(PDO::FETCH_ASSOC); //获取结果集中的所有数据
if(count($array)==0 || $rs==false)
return false;
else
return $array;
}elseif ($sqltype=="update" || $sqltype=="insert" || $sqltype=="delete"){
if($rs)
return true;
else
return false;
}
}
}
//分页类
class SepPage{
var $rs;
var $pagesize;
var $nowpage;
var $array;
var $conn;
var $sqlstr;
function ShowData($sqlstr,$conn,$pagesize,$nowpage){ //定义方法
if(!isset($nowpage) || $nowpage=="") //判断变量值是否为空
$this->nowpage=1; //定义每页起始页
else
$this->nowpage=$nowpage;
$this->pagesize=$pagesize; //定义每页输出的记录数
$this->conn=$conn; //连接数据库返回的标识
$this->sqlstr=$sqlstr; //执行的查询语句
$this->rs=$this->conn->PageExecute($this->sqlstr,$this->pagesize,$this->nowpage);
@$this->array=$this->rs->GetRows(); //获取记录数
if(count($this->array)==0 || $this->rs==false)
return false;
else
return $this->array;
}
function ShowPage($contentname,$utits,$anothersearchstr,$anothersearchstrs,$class){
$allrs=$this->conn->Execute($this->sqlstr); //执行查询语句
$record=count($allrs->GetRows()); //统计记录总数
$pagecount=ceil($record/$this->pagesize); //计算共有几页
$str.=$contentname." ".$record." ".$utits." 每页 ".$this->pagesize." ".$utits." 第 ".$this->rs->AbsolutePage()." 页/共 ".$pagecount." 页";
$str.=" ";
if(!$this->rs->AtFirstPage())
$str.="<a href=".$_SERVER['PHP_SELF']."?page=1¶meter1=".$anothersearchstr."¶meter2=".$anothersearchstrs." class=".$class.">首页</a>";
else
$str.="<font color='#555555'>首页</font>";
$str.=" ";
if(!$this->rs->AtFirstPage())
$str.="<a href=".$_SERVER['PHP_SELF']."?page=".($this->rs->AbsolutePage()-1)."¶meter1=".$anothersearchstr."¶meter2=".$anothersearchstrs." class=".$class.">上一页</a>";
else
$str.="<font color='#555555'>上一页</font>";
$str.=" ";
if(!$this->rs->AtLastPage())
$str.="<a href=".$_SERVER['PHP_SELF']."?page=".($this->rs->AbsolutePage()+1)."¶meter1=".$anothersearchstr."¶meter2=".$anothersearchstrs." class=".$class.">下一页</a>";
else
$str.="<font color='#555555'>下一页</font>";
$str.=" ";
if(!$this->rs->AtLastPage())
$str.="<a href=".$_SERVER['PHP_SELF']."?page=".$pagecount."¶meter1=".$anothersearchstr."¶meter2=".$anothersearchstrs." class=".$class.">尾页</a>";
else
$str.="<font color='#555555'>尾页</font>";
if(count($this->array)==0 || $this->rs==false)
return "";
else
return $str;
}
}
?>
--------------------------------------------------------------------------------
$this->user=$root;
$this->pwd=$root;
$this->dbname=$db_database24;
这三项,其他没修改;
在浏览器输入127.0.0.1/24后,就提示
Warning: Cannot modify header information - headers already sent by (output started at C:\AppServ\www\24\system\system.class.inc.php:1) in C:\AppServ\www\24\public.php on line 2
Warning: Cannot modify header information - headers already sent by (output started at C:\AppServ\www\24\system\system.class.inc.php:1) in C:\AppServ\www\24\links.php on line 2
Warning: Cannot modify header information - headers already sent by (output started at C:\AppServ\www\24\system\system.class.inc.php:1) in C:\AppServ\www\24\newhot.php on line 2
请教一下是不是什么地方修改不正确或是还要修改其他地方呢?
//数据库连接类
class ConnDB{
var $dbtype;
var $host;
var $user;
var $pwd;
var $dbname;
//构造方法
function ConnDB($dbtype,$host,$user,$pwd,$dbname){
$this->dbtype=$dbtype;
$this->host=$host;
$this->user=$user;
$this->pwd=$pwd;
$this->dbname=$dbname;
}
//实现数据库的连接并返回连接对象
function GetConnId(){
if($this->dbtype=="mysql" || $this->dbtype=="mssql"){
$dsn="$this->dbtype:host=$this->host;dbname=$this->dbname";
}else{
$dsn="$this->dbtype:dbname=$this->dbname";
}
try {
$conn = new PDO($dsn, $this->user, $this->pwd); //初始化一个PDO对象,就是创建了数据库连接对象$pdo
$conn->query("set names utf8");
return $conn;
} catch (PDOException $e) {
die ("Error!: " . $e->getMessage() . "<br/>");
}
}
}
//数据库管理类
class AdminDB{
function ExecSQL($sqlstr,$conn){
$sqltype=strtolower(substr(trim($sqlstr),0,6));
$rs=$conn->prepare($sqlstr); //准备查询语句
$rs->execute(); //执行查询语句,并返回结果集
if($sqltype=="select"){
$array=$rs->fetchAll(PDO::FETCH_ASSOC); //获取结果集中的所有数据
if(count($array)==0 || $rs==false)
return false;
else
return $array;
}elseif ($sqltype=="update" || $sqltype=="insert" || $sqltype=="delete"){
if($rs)
return true;
else
return false;
}
}
}
//分页类
class SepPage{
var $rs;
var $pagesize;
var $nowpage;
var $array;
var $conn;
var $sqlstr;
function ShowData($sqlstr,$conn,$pagesize,$nowpage){ //定义方法
if(!isset($nowpage) || $nowpage=="") //判断变量值是否为空
$this->nowpage=1; //定义每页起始页
else
$this->nowpage=$nowpage;
$this->pagesize=$pagesize; //定义每页输出的记录数
$this->conn=$conn; //连接数据库返回的标识
$this->sqlstr=$sqlstr; //执行的查询语句
$this->rs=$this->conn->PageExecute($this->sqlstr,$this->pagesize,$this->nowpage);
@$this->array=$this->rs->GetRows(); //获取记录数
if(count($this->array)==0 || $this->rs==false)
return false;
else
return $this->array;
}
function ShowPage($contentname,$utits,$anothersearchstr,$anothersearchstrs,$class){
$allrs=$this->conn->Execute($this->sqlstr); //执行查询语句
$record=count($allrs->GetRows()); //统计记录总数
$pagecount=ceil($record/$this->pagesize); //计算共有几页
$str.=$contentname." ".$record." ".$utits." 每页 ".$this->pagesize." ".$utits." 第 ".$this->rs->AbsolutePage()." 页/共 ".$pagecount." 页";
$str.=" ";
if(!$this->rs->AtFirstPage())
$str.="<a href=".$_SERVER['PHP_SELF']."?page=1¶meter1=".$anothersearchstr."¶meter2=".$anothersearchstrs." class=".$class.">首页</a>";
else
$str.="<font color='#555555'>首页</font>";
$str.=" ";
if(!$this->rs->AtFirstPage())
$str.="<a href=".$_SERVER['PHP_SELF']."?page=".($this->rs->AbsolutePage()-1)."¶meter1=".$anothersearchstr."¶meter2=".$anothersearchstrs." class=".$class.">上一页</a>";
else
$str.="<font color='#555555'>上一页</font>";
$str.=" ";
if(!$this->rs->AtLastPage())
$str.="<a href=".$_SERVER['PHP_SELF']."?page=".($this->rs->AbsolutePage()+1)."¶meter1=".$anothersearchstr."¶meter2=".$anothersearchstrs." class=".$class.">下一页</a>";
else
$str.="<font color='#555555'>下一页</font>";
$str.=" ";
if(!$this->rs->AtLastPage())
$str.="<a href=".$_SERVER['PHP_SELF']."?page=".$pagecount."¶meter1=".$anothersearchstr."¶meter2=".$anothersearchstrs." class=".$class.">尾页</a>";
else
$str.="<font color='#555555'>尾页</font>";
if(count($this->array)==0 || $this->rs==false)
return "";
else
return $str;
}
}
?>
--------------------------------------------------------------------------------
$this->user=$root;
$this->pwd=$root;
$this->dbname=$db_database24;
这三项,其他没修改;
在浏览器输入127.0.0.1/24后,就提示
Warning: Cannot modify header information - headers already sent by (output started at C:\AppServ\www\24\system\system.class.inc.php:1) in C:\AppServ\www\24\public.php on line 2
Warning: Cannot modify header information - headers already sent by (output started at C:\AppServ\www\24\system\system.class.inc.php:1) in C:\AppServ\www\24\links.php on line 2
Warning: Cannot modify header information - headers already sent by (output started at C:\AppServ\www\24\system\system.class.inc.php:1) in C:\AppServ\www\24\newhot.php on line 2
请教一下是不是什么地方修改不正确或是还要修改其他地方呢?
2014-07-26
13L
读者您好:
建议您从本书前面章节循序渐进的学习,您修改的这三项暴露了很多的问题。
我之前给您的回复:
“在项目24/system/system.inc.php文件中将数据库密码改为您安装数据库时所设置的密码。” 更加通俗的解释为:
将system.inc.php文件中的这行代码$connobj = new ConnDB("mysql","localhost","111","db_database24");中的111改为你自己设置的数据库密码,如果你的数据库密码是root,你只需要把这行改为:
$connobj = new ConnDB("mysql","localhost","root","db_database24");这样就可以了,其他的配置不需要修改。
学习技术,建议循序渐进,一步一个脚印,搜索能力和自学能力同样的重要。
建议您从本书前面章节循序渐进的学习,您修改的这三项暴露了很多的问题。
我之前给您的回复:
“在项目24/system/system.inc.php文件中将数据库密码改为您安装数据库时所设置的密码。” 更加通俗的解释为:
将system.inc.php文件中的这行代码$connobj = new ConnDB("mysql","localhost","111","db_database24");中的111改为你自己设置的数据库密码,如果你的数据库密码是root,你只需要把这行改为:
$connobj = new ConnDB("mysql","localhost","root","db_database24");这样就可以了,其他的配置不需要修改。
学习技术,建议循序渐进,一步一个脚印,搜索能力和自学能力同样的重要。