
正文
php数据库查找代码 php查询数据库内容表格
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
PHP数据库查询代码问题
首先你的sql语句写的有问题: $catsql="SELECT * FROM categories;";中的语句不用加“php数据库查找代码;”;
这里是出现了warning:当你的搜索结果是空集的时候php数据库查找代码,就会出现类似的情况
用if语句结合echo进行判断你的结果集是不是空的;
相关问答
Q1: PHP查询代码怎么写?
连接数据库
代码如下
?php
$conn = @mysql_connect("localhost","root","root") or die ("database error");
mysql_select_db("DB",$conn);
if (isset($_POST['submit'])){
$num=$_POST['num'];
$sql="SELECT num FROM TEST WHERE num=$num";
$tt=mysql_query($sql,$conn);
$row = mysql_fetch_assoc($tt);
echo "numphp数据库查找代码:".$row['num']."/br";
}
?
Q2: PHP数据库查询代码
php
变量
的话,要用数据库连接符,放在
字符串
里不会被转成值。
$sql
=
"
select
*
from
g4_board_file
where
bo_table
=
'$bo_table'
and
wr_id
=
'".$view[wr_id]'."'
order
by
bf_no";
把变量单独拿出来,再把字符串连起来。
Q3: 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;
}
# 如果查询结果为单条记录时使用,返回结果存储于数组 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 = @mysql_fetch_array($this-result, MYSQL_ASSOC);
//MySQL_ErrorMsg ("不能从查询结果中取得数据 $query");
if (!$this-result || !$this-rows)
return false;
return true;
}
# 移动到指定记录行,将该行结果储存于数组 data 中
function Fetch ($row) {
if(!@mysql_data_seek($this-result, $row))
//MySQL_ErrorMsg ("不能定位到指定数据行 $row");
return false;
$this-data = @mysql_fetch_array($this-result, MYSQL_ASSOC);
//MySQL_ErrorMsg ("不能提取指定数据行数据 $row");
if (!$this-data)
return false;
return true;
}
/* 以下方法将作用于 arows */
/* 此方法将作用于 iid */
function Insert ($query) {
$this-result = @mysql_query($query, $this-id);
if (!$this-result)
{
if ($this-debug)
MySQL_ErrorMsg ("不能执行查询(query): $query");
else
return false;
}
$this-arows = @mysql_affected_rows($this-id);
$this-iid = @mysql_insert_id($this-id);
return true;
}
function Update ($query) {
$this-result = @mysql_query($query, $this-id);
if (!$this-result)
{
if ($this-debug)
MySQL_ErrorMsg ("不能执行查询(query): $query");
else
return false;
}
$this-arows = @mysql_affected_rows($this-id);
if (!$this-arows || $this-arows == -1)
return false;
return true;
}
function Delete ($query) {
$this-result = @mysql_query($query, $this-id);
if (!$this-result)
{
if ($this-debug)
MySQL_ErrorMsg ("不能执行查询(query): $query");
else
return false;
}
$this-arows = @mysql_affected_rows($this-id);
return true;
}
function Error (){
return mysql_error()."(".mysql_errno().")";
}
function Errno (){
return mysql_errno();
}
}
/*
* MySQL_ErrorMsg
* 输出错误信息
*/
function MySQL_ErrorMsg ($msg) {
# 关闭可能影响字符显示的HTML代码
echo("/ul/dl/ol\n");
echo("/table/script\n");
# 错误信息
$text = "font color=\"#000000\" style=\"font-size: 9pt; line-height: 12pt\"p系统提示:".$msg."br";
$text .= "错误信息:";
$text .= mysql_error()."br";
$text .= "错误代码:".mysql_errno()."brbr";
$text .= "请稍候再试,如果问题仍然存在,请与 a href=\"mailto:wuqiong@igenus.org\"系统管理员/a 联系!";
$text .= "/font\n";
die($text);
}
}
?
一些细节的地方自己修改吧 主要是我在别的文件专门定义了全局变量,你看一遍,把应改的地方改一下就好了
php数据库查找代码的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于php查询数据库内容表格、php数据库查找代码的信息别忘了在本站进行查找喔。






