php查询数据代码怎么写 php查询数据库内容表格( 二 )


echo "numphp查询数据代码怎么写:".$row['num']."/br";
}
?
PHP中写一个数据库查询的类的方法代码要如何写?php
if(!defined("INCLUDE_MYSQL_OK")) {
define("INCLUDE_MYSQL_OK","");
class MySQL_class {
var $debug = true;
var $db,
$id,
$result,/* 查询结果指针 */
$rows,/* 查询结果行数 */
$fields,/* 查询结果列数 */
$data,/* 数据结果 */
$arows,/* 发生作用的纪录行数目 */
$iid;/* 上次插入操作后,可能存在的"AUTO_INCREMENT"属性字段的值,如果为"0",则为空 */
var $user, $pass, $host, $charset;
/*
* 请注意用户名和密码是否正确
*/
function Setup ($host, $user, $pass, $charset='utf8') {
$this-host = $host;
$this-user = $user;
$this-pass = $pass;
$this-charset = $charset;
}
function Connect ($db = "") {
global $CFG_MYSQL_INFO;
if (!$this-host) {
$this-host = $CFG_MYSQL_INFO["host"];
}
if (!$this-user) {
$this-user = $CFG_MYSQL_INFO["user"];/* 在这里作修改 */
}
if (!$this-pass) {
$this-pass = $CFG_MYSQL_INFO["passwd"]; /* 在这里作修改 */
}
if (!$this-charset) {
$this-charset = "utf8"; /* 在这里作修改 */
}
if (empty($db))
$this-db = $CFG_MYSQL_INFO["database"];
else
$this-db = $db;
$this-id = @mysql_connect($this-host, $this-user, $this-pass);
if (!$this-id)
return false;
$this-SelectDB($this-db);/* 定位到指定数据库 */
$this-Query("SET NAMES '".$this-charset."'");
return true;
}
function Close(){
@mysql_close($this-id);
}
function SelectDB ($db) {
if(!@mysql_select_db($db, $this-id))
return false;
else
return true;
}
function Begin () {
$this-result = @mysql_query("START TRANSACTION WITH CONSISTENT SNAPSHOT", $this-id);
if (!$this-result)
return false;
return true;
}
function Commit () {
$this-result = @mysql_query("COMMIT", $this-id);
if (!$this-result)
return false;
return true;
}
function Rollback () {
$this-result = @mysql_query("ROLLBACK", $this-id);
if (!$this-result)
return false;
return true;
}
function Escape ($str) {
$escstr = mysql_escape_string($str);
return $escstr;
}
# 普通查询功能,主要用于返回结果是多条记录的情况
# 请使用 Fetch 方法取得每条记录信息
function Query ($query) {
$this-result = @mysql_query($query, $this-id);
if (!$this-result)
{
if ($this-debug)
MySQL_ErrorMsg ("不能执行查询(query): $query");
else
return false;
}
$this-rows = @mysql_num_rows($this-result);
$this-fields = @mysql_num_fields($this-result);
if (!$this-rows) return false;
return true;
}
function QuerySql ($query) {
$ret = @mysql_query($query, $this-id);
if ($ret === false)
{
if ($this-debug)
MySQL_ErrorMsg ("不能执行查询(query): $query");
else
return false;
}
$this-result = $ret;
$this-rows = @mysql_num_rows($this-result);
$this-fields = @mysql_num_fields($this-result);
return true;
}
【php查询数据代码怎么写 php查询数据库内容表格】 # 如果查询结果为单条记录时使用,返回结果存储于数组 data 中
function QueryRow ($query) {
$this-result = @mysql_query($query, $this-id);
if (!$this-result)
{
if ($this-debug)
MySQL_ErrorMsg ("不能执行查询(query): $query");
else
return false;
}
$this-rows = @mysql_num_rows($this-result);
$this-data = https://www.04ip.com/post/@mysql_fetch_array($this-result, MYSQL_ASSOC);

推荐阅读