当前位置:Gxlcms > PHP教程 > mysql_query老是查不到数据

mysql_query老是查不到数据

时间:2021-07-01 10:21:17 帮助过:63人阅读

mysql_query总是查不到数据

$dbhost = "localhost";
$dbuser = "root";
$dbpassword = "";
$dbdatabase = "blogtastic";

$config_blogname = "Funny old world";
$config_author = "Pengsc";

$config_basedir = "htpp://127.0.0.1/blogtastic/";
?>

//require("config.php"); //include config.php
$db = mysql_connect($dbhost, $dbuser, $dbpassword);
if(!$db)
{
die('Could not connect: ' . mysql_error());
}

$db_selected = mysql_select_db($dbdatabase, $db);
if (!$db_selected)
{
die ("Can not use $dbdatabase : " . mysql_error());
}
?>




<?php echo $config_blogname; ?>







[home]





$sq1 = "SELECT entries.*, categories.cat From entries, categories
WHERE entries.cat_id = categories.id
ORDER BY dateposted DESC
LIMIT 1;";
mysql_query("set names 'utf8'"); //数据库
输出编码 应该与你的数据库编码保持一致.南昌网站建设公司百恒网络PHP工程师建议用UTF-8 国际标准编码.
$result = mysql_query($sql, $db);//执行一条 MySQL 查询
if($result)
{
echo "

ctergories and entries

";
echo "

ctergories and entries

";
echo "

ctergories and entries

";
echo "

ctergories and entries

";
echo "

ctergories and entries

";
$row = mysql_fetch_assoc($result); //从结果集中取得一行作为关联数组

print_r($row);

echo "

. "'>" . $row['subject'] . "


";
echo "In . "‘>" . $row['cat'] . " - Posted on " . date("D jS F Y g.iA", strtotime($row['dateposted'])) . "";
echo "

";
echo nl2br($row['body']);
echo "

";
}
else
{
print_r($row);
echo "no ctergories and entries";
}

?>





©





现在问题是,我直接在数据库中粘贴那个$sql中的查询语句以正常查询,就是通过mysql_query()查不到任何结果,这是什么原因????
------解决方案--------------------
有无错误信息?

$result = mysql_query($sql, $db) or die(mysql_error()); 这样写看看是否有报错信息。
------解决方案--------------------
SELECT entries.*, categories.cat From entries, categories
WHERE entries.cat_id = categories.id
ORDER BY dateposted DESC
LIMIT 1

在phpmyadin中执行可以查询到吗?
------解决方案--------------------
$sq1 = "SELECT entries.*, categories.cat From entries, categories
WHERE entries.cat_id = categories.id
ORDER BY dateposted DESC
LIMIT 1;";

去掉LIMIT 1后面那个分号。


------解决方案--------------------
$sq1 = "SELECT entries.*, categories.cat From entries, categories
WHERE entries.cat_id = categories.id
ORDER BY dateposted DESC
LIMIT 1;";

多了;
------解决方案--------------------
先要确定SQL是不是正确连接,如果可以执行一条简单的查询语句看看数据库选择,表前缀是不是正确的,如果这些都是正确的,那就是SQL查询语句有问题

如果你是myphpadmin的话把查询条件复制进去执行下,就知道是不是语句错误了

人气教程排行