欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

mysql_query老是查不到数据

程序员文章站 2022-05-23 23:16:25
...
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; ?>










$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的话把查询条件复制进去执行下,就知道是不是语句错误了
mysql_query老是查不到数据

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。

相关文章

相关视频