$res = $db-query($sql);
$info = array();//定义数组
while($row=$db-fetchRow($res))
{
$arr['id']= $row['id'];
$arr['title']= $row['title'];
$info[]= $arr;
}
可以在显示的地方用:
foreach($info as $i)
{
echo $i['title']."br /";
}
或是直接使用while
还用另一种调用方式:
$here_area = $db-getRow("select areaid,areaname from {$table}area where areaid='$areaid'");
$here[] = array('name'=$here_area['areaname'],'id'=$here_area['areaid']);
测试通过,因为我正在使用.....................................
config.php代码:
?php
$db_host= "localhost";
$db_name= "test";
$db_user= "root";
$db_pass= "";
$table= "mini_";
$charset= "gb2312";
$dbcharset = "gbk";
?
mysql.class.php代码:
?php
class mysql
{
var $link= NULL;
//自动执行__construct php5类构建方法,如果PHP4和PHP5同时使用会自动使用PHP5的方法
function __construct($dbhost, $dbuser, $dbpw, $dbname = '', $pconnect = 0, $quiet = 0)
{
//自动执行时调用mysql函数
$this-mysql($dbhost, $dbuser, $dbpw, $dbname, $pconnect, $quiet);
}
//php4类构建方法,如果没有 __construct 就自动执行此功能
function mysql($dbhost, $dbuser, $dbpw, $dbname = '', $pconnect = 0, $quiet = 0)
{
if ($quiet)
{
$this-connect($dbhost, $dbuser, $dbpw, $dbname, $pconnect, $quiet);
}
else
{
$this-settings = array(
'dbhost'= $dbhost,
'dbuser'= $dbuser,
'dbpw'= $dbpw,
'dbname'= $dbname,
'charset'= $charset,
'pconnect' = $pconnect
);
}
}
function connect($dbhost, $dbuser, $dbpw, $dbname = '', $pconnect = 0, $quiet = 0)
{
global $dbcharset;
if ($pconnect)
{
if (!($this-link = @mysql_pconnect($dbhost, $dbuser, $dbpw)))
{
if (!$quiet)
{
$this-ErrorMsg("Can't pConnect MySQL Server($dbhost)!");
}
return false;
}
}
else
{
if (PHP_VERSION = '4.2')
{
$this-link = @mysql_connect($dbhost, $dbuser, $dbpw, true);
}
else
{
$this-link = @mysql_connect($dbhost, $dbuser, $dbpw);
mt_srand((double)microtime() * 1000000);
}
if (!$this-link)
{
if (!$quiet)
{
$this-ErrorMsg("Can't Connect MySQL Server($dbhost)!");
}
return false;
}
}
$this-dbhash= md5($this-root_path . $dbhost . $dbuser . $dbpw . $dbname);
$this-version = mysql_get_server_info($this-link);
if ($this-version'4.1')
{
if ($dbcharset != 'latin1')
{
mysql_query("SET character_set_connection=$dbcharset, character_set_results=$dbcharset, character_set_client=binary", $this-link);
}
if ($this-version'5.0.1')
{
mysql_query("SET sql_mode=''", $this-link);
}
}
if ($dbname)
{
if (mysql_select_db($dbname, $this-link) === false )
{
if (!$quiet)
{
$this-ErrorMsg("Can't select MySQL database($dbname)!");
}
return false;
}
else
{
return true;
}
}
else
{
return true;
}
}
function query($sql, $type = '')
{
if ($this-link === NULL)
{
$this-connect($this-settings['dbhost'], $this-settings['dbuser'], $this-settings['dbpw'], $this-settings['dbname'], $this-settings['charset'], $this-settings['pconnect']);
$this-settings = array();
}
if ($this-queryCount++ = 99)
{
$this-queryLog[] = $sql;
}
if ($this-queryTime == '')
{
if (PHP_VERSION = '5.0.0')
{
$this-queryTime = microtime(true);
}
else
{
$this-queryTime = microtime();
推荐阅读
- 吐司的直播话术,吐司的直播话术怎么说
- 灯饰erp管理系统免费版,灯饰erp软件
- 下载挖土机,下载挖土机模式
- 直播时代少年团素材,时代少年团素材视频无水印
- linux常用命令视频 linux50个常用命令
- 致钛硬盘保修怎么查,致钛硬盘保修怎么查保修期
- cpu线路图用什么画,cpu内部线路图
- xboxone飞行游戏推荐,xbox飞行模拟游戏
- mysql里绝对值怎么写 mysql怎么设置取值范围