当前位置:首页 » 编程语言 » phpdb

phpdb

发布时间: 2022-02-08 05:18:08

php db类的使用

你的query()有返回值,你可以把代码改成这样再试试
function fn_select($tabl){
return $this->query("select * from $tabl order by id desc");

}

你没有用到自己定义的
function fetch_array($query, $result_type = MYsql_ASSOC) {
return @mysql_fetch_array($query, $result_type);
}

你试着在后面加上
$row=$db->fetch_array($a,MYSQL_NUM);
print_r($row);
应该就看到结果了

www.365php.net 365PHP培训与交流平台 欢迎光临

⑵ php db.class怎么写

<?php
class Db{
public $host;
public $username;
public $password;
public $database;
public $conn;
public $table;
public $sql;
public $field = '*';

function __construct($host,$username,$password,$database){
$this->host = $host;
$this->username = $username;
$this->password = $password;
$this->database = $database;
$this->connect();
}

function connect(){

$this->conn = new mysqli($this->host, $this->username, $this->password,$this->database);

if ($this->conn->connect_error) {
die("连接失败: " . $this->conn->connect_error);
}
}

function M($table){
$this->table = $table;
return $this;
}

function where($array){
$this->sql = '';
$sql = 'where ';
$one = '';
if($array){
if(is_array($array)){
foreach($array as $key=>$vo){
$one .= '`'.$key.'` = "'.$vo.'" and';
}
$one = trim($one,'and');
$sql .= $one;
$this->sql = $sql;
}else{
$sql .= $array;
$this->sql = $sql;

}
}
return $this;
}

function add($array){
$sql = 'insert into `'.$this->table.'` (';
$one = '';
$two = '';
if($array){
if(is_array($array)){
foreach($array as $key=>$vo){
$one .= '`'.$key.'` ,';
$two .= '"'.$vo.'",';
}
$one = trim($one,',');
$two = trim($two,',');
if($one && $two){
$sql .= $one.') values ('.$two.')';
$this->sql = $sql;
$r = $this->conn->query($this->sql);
if($r){
return mysqli_insert_id($this->conn);
}else{
return false;
}
}
}else{
exit('非数组');
}
}else{
exit('数组为空');
}
}

function select(){
$array = '';
$sql = 'select '.$this->field.' from `'.$this->table.'`'.$this->sql;
$result = $this->conn->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
$array[] = $row;
}
}
return $array;
}
function find(){
$row = '';
$sql = 'select '.$this->field.' from `'.$this->table.'`'.$this->sql.'limit 1';
$result = $this->conn->query($sql);
if($result){
$row = $result->fetch_assoc();
}

return $row;
}
function edit($array){
$sql = 'update `'.$this->table.'` set ';
$one = '';
if($array){
if(is_array($array)){
foreach($array as $key=>$vo){
$one .= '`'.$key.'` = "'.$vo.'",';
}
$one = trim($one,',');
$sql .= $one.' '.$this->sql;
}else{
$sql .= $array.' '.$this->sql;
}
$r = $this->conn->query($sql);
if($r){
return true;
}else{
return false;
}
}else{
exit('未接收到参数');
}
}

function del(){
$sql = 'delete from `'.$this->table.'` ';
$sql .= $this->sql;
$r = $this->conn->query($sql);
if($r){
return true;
}else{
return false;
}
}
function order($data){
$this->sql = $this->sql.' order by '.$data;
return $this;
}

function limit($data){
$this->sql = $this->sql.' limit '.$data;
return $this;
}
function field($data){
$this->field = $data;
return $this;
}

}

?>

⑶ php程序中的.db文件怎么打开

什么打不开 你是怎么打的啊

⑷ php能否使用mysql语句操作.db文件啊

它所得到的那个$ret,你需要使用mysql_fetch_row()、mysql_fetch_assoc()、mysql_fetch_array()以及mysql_fetch_field()这样的函数来取得它的结果集才行哦亲。

你的程序在:

$ret = mysql_query($sql,$con);
一行下面,需要加上:
$result = mysql_fetch_array($ret);

之后,你再print_r或者var_mp($ret),你就可以看到结果了哦。

⑸ 为什么PHP函数里边的$db需要写成global $db才能正常

作用范围的问题,函数里面是一个封闭的环境,如果不是全局变量的话,是不能在函数里面使用的。

global $db, 声明 $db 的作用范围为全局,就可以在函数里面使用了

回复能不能正常点,还要脑补的, - -!,首先,你可以在第一次声明的时候声明 global 这个看你的需求,其次,函数里面去include 的文件,我是没有遇到过谁这么写过,初次声明的时候 global 就行了,没必要去钻牛角尖。估计不能起作用的问题是,include_once 只引入一次文件,第二次 include_once同一文件的时候是忽略的,换成 include 的试试。

⑹ 求一个php写的DB类

这个是ECSHOP的数据库类,你可以参考一下:
class cls_mysql

{
var $link_id = NULL;
var $settings = array();
var $queryCount = 0;
var $queryTime = '';
var $queryLog = array();
var $max_cache_time = 300; // 最大的缓存时间,以秒为单位
var $cache_data_dir = 'temp/query_caches/';
var $root_path = '';
var $error_message = array();
var $platform = '';
var $version = '';
var $dbhash = '';
var $starttime = 0;
var $timeline = 0;
var $timezone = 0;
var $mysql_config_cache_file_time = 0;
var $mysql_disable_cache_tables = array(); // 不允许被缓存的表,遇到将不会进行缓存
function __construct($dbhost, $dbuser, $dbpw, $dbname = '', $charset = 'gbk', $pconnect = 0, $quiet = 0)
{
$this->cls_mysql($dbhost, $dbuser, $dbpw, $dbname, $charset, $pconnect, $quiet);
}
function cls_mysql($dbhost, $dbuser, $dbpw, $dbname = '', $charset = 'gbk', $pconnect = 0, $quiet = 0)
{
if (defined('EC_CHARSET'))
{
$charset = strtolower(str_replace('-', '', EC_CHARSET));
}
if (defined('ROOT_PATH') && !$this->root_path)
{
$this->root_path = ROOT_PATH;
}
if ($quiet)
{
$this->connect($dbhost, $dbuser, $dbpw, $dbname, $charset, $pconnect, $quiet);
}
else
{
$this->settings = array(
'dbhost' => $dbhost,
'dbuser' => $dbuser,
'dbpw' => $dbpw,
'dbname' => $dbname,
'charset' => $charset,
'pconnect' => $pconnect
);
}
}
function connect($dbhost, $dbuser, $dbpw, $dbname = '', $charset = 'utf8', $pconnect = 0, $quiet = 0)
{
if ($pconnect)
{
if (!($this->link_id = @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_id = @mysql_connect($dbhost, $dbuser, $dbpw, true);
}
else
{
$this->link_id = @mysql_connect($dbhost, $dbuser, $dbpw);
mt_srand((double)microtime() * 1000000); // 对 PHP 4.2 以下的版本进行随机数函数的初始化工作
}
if (!$this->link_id)
{
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_id);
/* 如果mysql 版本是 4.1+ 以上,需要对字符集进行初始化 */
if ($this->version > '4.1')
{
if ($charset != 'latin1')
{
mysql_query("SET character_set_connection=$charset, character_set_results=$charset, character_set_client=binary", $this->link_id);
}
if ($this->version > '5.0.1')
{
mysql_query("SET sql_mode=''", $this->link_id);
}
}
$sqlcache_config_file = $this->root_path . $this->cache_data_dir . 'sqlcache_config_file_' . $this->dbhash . '.php';
@include($sqlcache_config_file);
$this->starttime = time();
if ($this->max_cache_time && $this->starttime > $this->mysql_config_cache_file_time + $this->max_cache_time)
{
if ($dbhost != '.')
{
$result = mysql_query("SHOW VARIABLES LIKE 'basedir'", $this->link_id);
$row = mysql_fetch_assoc($result);
if (!empty($row['Value']{1}) && $row['Value']{1} == ':' && !empty($row['Value']{2}) && $row['Value']{2} == "\\")
{
$this->platform = 'WINDOWS';
}
else
{
$this->platform = 'OTHER';
}
}
else
{
$this->platform = 'WINDOWS';
}
if ($this->platform == 'OTHER' &&
($dbhost != '.' && strtolower($dbhost) != 'localhost:3306' && $dbhost != '127.0.0.1:3306') ||
(PHP_VERSION >= '5.1' && date_default_timezone_get() == 'UTC'))
{
$result = mysql_query("SELECT UNIX_TIMESTAMP() AS timeline, UNIX_TIMESTAMP('" . date('Y-m-d H:i:s', $this->starttime) . "') AS timezone", $this->link_id);
$row = mysql_fetch_assoc($result);
if ($dbhost != '.' && strtolower($dbhost) != 'localhost:3306' && $dbhost != '127.0.0.1:3306')
{
$this->timeline = $this->starttime - $row['timeline'];
}
if (PHP_VERSION >= '5.1' && date_default_timezone_get() == 'UTC')
{
$this->timezone = $this->starttime - $row['timezone'];
}
}
$content = '<' . "?php\r\n" .
'$this->mysql_config_cache_file_time = ' . $this->starttime . ";\r\n" .
'$this->timeline = ' . $this->timeline . ";\r\n" .
'$this->timezone = ' . $this->timezone . ";\r\n" .
'$this->platform = ' . "'" . $this->platform . "';\r\n?" . '>';
@file_put_contents($sqlcache_config_file, $content);
}
/* 选择数据库 */
if ($dbname)
{
if (mysql_select_db($dbname, $this->link_id) === false )
{
if (!$quiet)
{
$this->ErrorMsg("Can't select MySQL database($dbname)!");
}
return false;
}
else
{
return true;
}
}
else
{
return true;
}
}
function select_database($dbname)
{
return mysql_select_db($dbname, $this->link_id);
}
function set_mysql_charset($charset)
{
/* 如果mysql 版本是 4.1+ 以上,需要对字符集进行初始化 */
if ($this->version > '4.1')
{
if (in_array(strtolower($charset), array('gbk', 'big5', 'utf-8', 'utf8')))
{
$charset = str_replace('-', '', $charset);
}
if ($charset != 'latin1')
{
mysql_query("SET character_set_connection=$charset, character_set_results=$charset, character_set_client=binary", $this->link_id);
}
}
}
function fetch_array($query, $result_type = MYSQL_ASSOC)
{
return mysql_fetch_array($query, $result_type);
}
function query($sql, $type = '')
{
if ($this->link_id === 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();
}
}
/* 当当前的时间大于类初始化时间的时候,自动执行 ping 这个自动重新连接操作 */
if (PHP_VERSION >= '4.3' && time() > $this->starttime + 1)
{
mysql_ping($this->link_id);
}
if (!($query = mysql_query($sql, $this->link_id)) && $type != 'SILENT')
{
$this->error_message[]['message'] = 'MySQL Query Error';
$this->error_message[]['sql'] = $sql;
$this->error_message[]['error'] = mysql_error($this->link_id);
$this->error_message[]['errno'] = mysql_errno($this->link_id);
$this->ErrorMsg();
return false;
}
if (defined('DEBUG_MODE') && (DEBUG_MODE & 8) == 8)
{
$logfilename = $this->root_path . DATA_DIR . '/mysql_query_' . $this->dbhash . '_' . date('Y_m_d') . '.log';
$str = $sql . "\n\n";
if (PHP_VERSION >= '5.0')
{
file_put_contents($logfilename, $str, FILE_APPEND);
}
else
{
$fp = @fopen($logfilename, 'ab+');
if ($fp)
{
fwrite($fp, $str);
fclose($fp);
}
}
}
return $query;
}
function affected_rows()
{
return mysql_affected_rows($this->link_id);
}
function error()
{
return mysql_error($this->link_id);
}
function errno()
{
return mysql_errno($this->link_id);
}
function result($query, $row)
{
return @mysql_result($query, $row);
}
function num_rows($query)
{
return mysql_num_rows($query);
}
function num_fields($query)
{
return mysql_num_fields($query);
}
function free_result($query)
{
return mysql_free_result($query);
}
function insert_id()
{
return mysql_insert_id($this->link_id);
}
function fetchRow($query)
{
return mysql_fetch_assoc($query);
}
function fetch_fields($query)
{
return mysql_fetch_field($query);
}
function version()
{
return $this->version;
}
function ping()
{
if (PHP_VERSION >= '4.3')
{
return mysql_ping($this->link_id);
}
else
{
return false;
}
}
function escape_string($unescaped_string)
{
if (PHP_VERSION >= '4.3')
{
return mysql_real_escape_string($unescaped_string);
}
else
{
return mysql_escape_string($unescaped_string);
}
}
function close()
{
return mysql_close($this->link_id);
}
function ErrorMsg($message = '', $sql = '')
{
if ($message)
{
echo "<b>ECSHOP info</b>: $message\n\n<br /><br />";
//print('<a href="http://faq.comsenz.com/?type=mysql&dberrno=2003&dberror=Can%27t%20connect%20to%20MySQL%20server%20on" target="_blank">http://faq.comsenz.com/</a>');
}
else
{
echo "<b>MySQL server error report:";
print_r($this->error_message);
//echo "<br /><br /><a href='http://faq.comsenz.com/?type=mysql&dberrno=" . $this->error_message[3]['errno'] . "&dberror=" . urlencode($this->error_message[2]['error']) . "' target='_blank'>http://faq.comsenz.com/</a>";
}
exit;
}

/* 仿真 Adodb 函数 */
function selectLimit($sql, $num, $start = 0)
{
if ($start == 0)
{
$sql .= ' LIMIT ' . $num;
}
else
{
$sql .= ' LIMIT ' . $start . ', ' . $num;
}
return $this->query($sql);
}
function getOne($sql, $limited = false)
{
if ($limited == true)
{
$sql = trim($sql . ' LIMIT 1');
}
$res = $this->query($sql);
if ($res !== false)
{
$row = mysql_fetch_row($res);
if ($row !== false)
{
return $row[0];
}
else
{
return '';
}
}
else
{
return false;
}
}
function getOneCached($sql, $cached = 'FILEFIRST')
{
$sql = trim($sql . ' LIMIT 1');
$cachefirst = ($cached == 'FILEFIRST' || ($cached == 'MYSQLFIRST' && $this->platform != 'WINDOWS')) && $this->max_cache_time;
if (!$cachefirst)
{
return $this->getOne($sql, true);
}
else
{
$result = $this->getSqlCacheData($sql, $cached);
if (empty($result['storecache']) == true)
{
return $result['data'];
}
}
$arr = $this->getOne($sql, true);
if ($arr !== false && $cachefirst)
{
$this->setSqlCacheData($result, $arr);
}
return $arr;
}

⑺ 在PHP中$db=new DB();是什么意思

new 是实例化一个对象
而DB 就是那个对象的名称 也可以叫类名
$db = new DB; // 将DB这个对象实例化后赋予变量$db
$db->query(); // 那么这个query()函数 就是DB类里的一个方法

⑻ db.php这里面这是什么意思呀,数据库什么的

db.php是一个php页面,不是数据库,而且也不知道用的什么数据库
PHP(外文名:PHP: Hypertext Preprocessor,中文名:“超文本预处理器”)是一种通用开源脚本语言。语法吸收了C语言、Java和Perl的特点,利于学习,使用广泛,主要适用于Web开发领域。PHP 独特的语法混合了C、Java、Perl以及PHP自创的语法。它可以比CGI或者Perl更快速地执行动态网页。

⑼ php+txtdb 新手教程

我对 TXTDB 还算比较自信。你有兴趣来找我。 42696883

⑽ PHP语句中的 $db->query($sql); 请问这个->符号是什么 以及他的作用。

$db 是一个实例化好的数据库类,query是这个类里面的一个方法,$db->query($sql); 就是访问$db类里的query方法,->相当于访问类里面方法的一个语法而已。操作方法如下:

1、首先写上这个程序的注释内容,#创建一个类并实例化它。

热点内容
scratch少儿编程课程 发布:2025-04-16 17:11:44 浏览:628
荣耀x10从哪里设置密码 发布:2025-04-16 17:11:43 浏览:357
java从入门到精通视频 发布:2025-04-16 17:11:43 浏览:74
php微信接口教程 发布:2025-04-16 17:07:30 浏览:298
android实现阴影 发布:2025-04-16 16:50:08 浏览:788
粉笔直播课缓存 发布:2025-04-16 16:31:21 浏览:338
机顶盒都有什么配置 发布:2025-04-16 16:24:37 浏览:203
编写手游反编译都需要学习什么 发布:2025-04-16 16:19:36 浏览:801
proteus编译文件位置 发布:2025-04-16 16:18:44 浏览:357
土压缩的本质 发布:2025-04-16 16:13:21 浏览:583