在三十讲遇到这样一个问题就是运行代码时出现错误 Fatal error: Call to undefined method mysql::fetch_array() in D:\WWW\news\index.php on line 12
,我把mysql::fetch_array() 改成mysql::fetch_row() 又出现Fatal error: Call to undefined method mysql::fetch_row() in D:\WWW\news\index.php on line 12
,以至我读不到{$row[1]},具体的代码如下,
//.......smarty_inc.php
<?php
include_once("Smarty/Smarty.class.php"); //包含smarty类文件$smarty = new Smarty(); //建立smarty实例对象$smarty
$smarty->config_dir="Smarty/Config_File.class.php"; // 目录变量
$smarty->template_dir = "./templates"; //设置模板目录
$smarty->compile_dir = "./templates_c"; //设置编译目录
$smarty->cache_dir = "./caches/"; //缓存目录
$smarty->caching = true; //开启缓存,为flase的时侯缓存无效
$smarty->cache_lifetime = 600; //缓存时间
//----------------------------------------------------//左右边界符,默认为{},但实际应用当中容易与JavaScript相冲突//----------------------------------------------------$smarty->left_delimiter = "{";$smarty->right_delimiter = "}";
?>
//......mysql_class.php
<?php
/*
* class mysql
* www.php100.com 编辑器教程
* Window - Preferences - PHPeclipse - PHP - Code Templates
*/ class mysql{
private $host;
private $name;
private $pass;
private $table;
private $ut; function __construct($host,$name,$pass,$table,$ut){
$this->host=$host;
$this->name=$name;
$this->pass=$pass;
$this->table=$table;
$this->ut=$ut;
$this->connect(); }
function connect(){
$link=mysql_connect($this->host,$this->name,$this->pass) or die ("连接错误");
mysql_select_db($this->table,$link) or die("没该数据库:".$this->table);
mysql_query("SET NAMES '$this->ut'");
}
function query($sql,$type= ''){
if(!($query = mysql_query($sql))) $this->show('say:',$sql);
return $query;
}
function show($message ='',$sql= ''){
if(!$sql) echo $message;
else echo $message.'<br>'.$sql;
}//============== function fn_insert($table,$name,$value){ $this->query("insert into $table ($name) values($value)"); }
}
$db = new mysql('localhost','root','','test',"GBK");?>
//.........index.php
<?php
/*
* 0000000000000000
*
* www.php100.com剪辑器教程
* Window - Preferences - PHPeclipse - PHP - Code Templates
*/include("smarty_inc.php");
include("mysql_class.php");
if($_GET[id]){
$sql="SELECT * FROM `php100` WHERE id=".$_GET[id];
$query=$db->query($sql);
$row=$db->fetch_row($query);
}
$smarty->assign("row",$row);
$smarty->display("index.htm");?>
//.........index.htm
标题:{$row[1]}<br>
运行后只有标题:没有{$row[1]}的内容
图片:
MYSQL与Smarty的应用
在三十讲遇到这样一个问题就是运行代码时出现错误 Fatal error: Call to undefined method mysql::fetch_array() in D:\WWW\news\index.php on line 12
,我把mysql::fetch_array() 改成mysql::fetch_row() 又出现Fatal error: Call to undefined method mysql::fetch_row() in D:\WWW\news\index.php on line 12
,以至我读不到{$row[1]},具体的代码如下,
//.......smarty_inc.php
<?php
include_once("Smarty/Smarty.class.php"); //包含smarty类文件$smarty = new Smarty(); //建立smarty实例对象$smarty
$smarty->config_dir="Smarty/Config_File.class.php"; // 目录变量
$smarty->template_dir = "./templates"; //设置模板目录
$smarty->compile_dir = "./templates_c"; //设置编译目录
$smarty->cache_dir = "./caches/"; //缓存目录
$smarty->caching = true; //开启缓存,为flase的时侯缓存无效
$smarty->cache_lifetime = 600; //缓存时间
//----------------------------------------------------//左右边界符,默认为{},但实际应用当中容易与JavaScript相冲突//----------------------------------------------------$smarty->left_delimiter = "{";$smarty->right_delimiter = "}";
?>
//......mysql_class.php
<?php
/*
* class mysql
* www.php100.com 编辑器教程
* Window - Preferences - PHPeclipse - PHP - Code Templates
*/ class mysql{
private $host;
private $name;
private $pass;
private $table;
private $ut; function __construct($host,$name,$pass,$table,$ut){
$this->host=$host;
$this->name=$name;
$this->pass=$pass;
$this->table=$table;
$this->ut=$ut;
$this->connect(); }
function connect(){
$link=mysql_connect($this->host,$this->name,$this->pass) or die ("连接错误");
mysql_select_db($this->table,$link) or die("没该数据库:".$this->table);
mysql_query("SET NAMES '$this->ut'");
}
function query($sql,$type= ''){
if(!($query = mysql_query($sql))) $this->show('say:',$sql);
return $query;
}
function show($message ='',$sql= ''){
if(!$sql) echo $message;
else echo $message.'<br>'.$sql;
}//============== function fn_insert($table,$name,$value){ $this->query("insert into $table ($name) values($value)"); }
}
$db = new mysql('localhost','root','','test',"GBK");?>
//.........index.php
<?php
/*
* 0000000000000000
*
* www.php100.com剪辑器教程
* Window - Preferences - PHPeclipse - PHP - Code Templates
*/include("smarty_inc.php");
include("mysql_class.php");
if($_GET[id]){
$sql="SELECT * FROM `php100` WHERE id=".$_GET[id];
$query=$db->query($sql);
$row=$db->fetch_row($query);
}
$smarty->assign("row",$row);
$smarty->display("index.htm");?>
//.........index.htm
标题:{$row[1]}<br>
运行后只有标题:没有{$row[1]}的内容
图片:
,我把mysql::fetch_array() 改成mysql::fetch_row() 又出现Fatal error: Call to undefined method mysql::fetch_row() in D:\WWW\news\index.php on line 12
,以至我读不到{$row[1]},具体的代码如下,
//.......smarty_inc.php
<?php
include_once("Smarty/Smarty.class.php"); //包含smarty类文件$smarty = new Smarty(); //建立smarty实例对象$smarty
$smarty->config_dir="Smarty/Config_File.class.php"; // 目录变量
$smarty->template_dir = "./templates"; //设置模板目录
$smarty->compile_dir = "./templates_c"; //设置编译目录
$smarty->cache_dir = "./caches/"; //缓存目录
$smarty->caching = true; //开启缓存,为flase的时侯缓存无效
$smarty->cache_lifetime = 600; //缓存时间
//----------------------------------------------------//左右边界符,默认为{},但实际应用当中容易与JavaScript相冲突//----------------------------------------------------$smarty->left_delimiter = "{";$smarty->right_delimiter = "}";
?>
//......mysql_class.php
<?php
/*
* class mysql
* www.php100.com 编辑器教程
* Window - Preferences - PHPeclipse - PHP - Code Templates
*/ class mysql{
private $host;
private $name;
private $pass;
private $table;
private $ut; function __construct($host,$name,$pass,$table,$ut){
$this->host=$host;
$this->name=$name;
$this->pass=$pass;
$this->table=$table;
$this->ut=$ut;
$this->connect(); }
function connect(){
$link=mysql_connect($this->host,$this->name,$this->pass) or die ("连接错误");
mysql_select_db($this->table,$link) or die("没该数据库:".$this->table);
mysql_query("SET NAMES '$this->ut'");
}
function query($sql,$type= ''){
if(!($query = mysql_query($sql))) $this->show('say:',$sql);
return $query;
}
function show($message ='',$sql= ''){
if(!$sql) echo $message;
else echo $message.'<br>'.$sql;
}//============== function fn_insert($table,$name,$value){ $this->query("insert into $table ($name) values($value)"); }
}
$db = new mysql('localhost','root','','test',"GBK");?>
//.........index.php
<?php
/*
* 0000000000000000
*
* www.php100.com剪辑器教程
* Window - Preferences - PHPeclipse - PHP - Code Templates
*/include("smarty_inc.php");
include("mysql_class.php");
if($_GET[id]){
$sql="SELECT * FROM `php100` WHERE id=".$_GET[id];
$query=$db->query($sql);
$row=$db->fetch_row($query);
}
$smarty->assign("row",$row);
$smarty->display("index.htm");?>
//.........index.htm
标题:{$row[1]}<br>
运行后只有标题:没有{$row[1]}的内容
图片:
MYSQL与Smarty的应用
在三十讲遇到这样一个问题就是运行代码时出现错误 Fatal error: Call to undefined method mysql::fetch_array() in D:\WWW\news\index.php on line 12
,我把mysql::fetch_array() 改成mysql::fetch_row() 又出现Fatal error: Call to undefined method mysql::fetch_row() in D:\WWW\news\index.php on line 12
,以至我读不到{$row[1]},具体的代码如下,
//.......smarty_inc.php
<?php
include_once("Smarty/Smarty.class.php"); //包含smarty类文件$smarty = new Smarty(); //建立smarty实例对象$smarty
$smarty->config_dir="Smarty/Config_File.class.php"; // 目录变量
$smarty->template_dir = "./templates"; //设置模板目录
$smarty->compile_dir = "./templates_c"; //设置编译目录
$smarty->cache_dir = "./caches/"; //缓存目录
$smarty->caching = true; //开启缓存,为flase的时侯缓存无效
$smarty->cache_lifetime = 600; //缓存时间
//----------------------------------------------------//左右边界符,默认为{},但实际应用当中容易与JavaScript相冲突//----------------------------------------------------$smarty->left_delimiter = "{";$smarty->right_delimiter = "}";
?>
//......mysql_class.php
<?php
/*
* class mysql
* www.php100.com 编辑器教程
* Window - Preferences - PHPeclipse - PHP - Code Templates
*/ class mysql{
private $host;
private $name;
private $pass;
private $table;
private $ut; function __construct($host,$name,$pass,$table,$ut){
$this->host=$host;
$this->name=$name;
$this->pass=$pass;
$this->table=$table;
$this->ut=$ut;
$this->connect(); }
function connect(){
$link=mysql_connect($this->host,$this->name,$this->pass) or die ("连接错误");
mysql_select_db($this->table,$link) or die("没该数据库:".$this->table);
mysql_query("SET NAMES '$this->ut'");
}
function query($sql,$type= ''){
if(!($query = mysql_query($sql))) $this->show('say:',$sql);
return $query;
}
function show($message ='',$sql= ''){
if(!$sql) echo $message;
else echo $message.'<br>'.$sql;
}//============== function fn_insert($table,$name,$value){ $this->query("insert into $table ($name) values($value)"); }
}
$db = new mysql('localhost','root','','test',"GBK");?>
//.........index.php
<?php
/*
* 0000000000000000
*
* www.php100.com剪辑器教程
* Window - Preferences - PHPeclipse - PHP - Code Templates
*/include("smarty_inc.php");
include("mysql_class.php");
if($_GET[id]){
$sql="SELECT * FROM `php100` WHERE id=".$_GET[id];
$query=$db->query($sql);
$row=$db->fetch_row($query);
}
$smarty->assign("row",$row);
$smarty->display("index.htm");?>
//.........index.htm
标题:{$row[1]}<br>
运行后只有标题:没有{$row[1]}的内容
图片:
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货