-4

我正在尝试在页面上查看(打印或回显)以下内容发送的实际查询:

$req1 = mysql_query('select m1.id, m1.title, m1.date_time, count(m2.id) as reps, users.username as userid, users.username from pm as m1, pm as m2,users where ((m1.user1="'.$_SESSION['username'].'" and m1.user1read="no" and users.id=m1.user2) or (m1.user2="'.$_SESSION['username'].'" and m1.user2read="no" and users.id=m1.user1)) and m1.id2="1" and m2.id=m1.id group by m1.id order by m1.id desc'); 

我试过在网上寻找一种方法来做到这一点,但“echo $req1”只是返回一个资源 ID。出了点问题,可能是用户名变量,它没有返回任何记录。有人可以解释如何获取实际的查询,因为它使用用户名变量等运行以打印?我不知道该怎么做。

提前谢谢你的天才!!!:)

4

2 回答 2

3
$sql = 'select m1.id, m1.title, m1.date_time, count(m2.id) as reps, users.username as userid, users.username from pm as m1, pm as m2,users where ((m1.user1="'.$_SESSION['username'].'" and m1.user1read="no" and users.id=m1.user2) or (m1.user2="'.$_SESSION['username'].'" and m1.user2read="no" and users.id=m1.user1)) and m1.id2="1" and m2.id=m1.id group by m1.id order by m1.id desc';
var_dump($sql);
//then to run it
$req1 = mysql_query($sql);

虽然这些mysql_*功能已被弃用 - 您应该使用mysqliPDO

于 2013-08-23T15:33:53.833 回答
0

你可以查看Mysql的日志。在 Linux 系统上,它们位于 /var/log 目录中。您还需要使用特定选项启动 Mysql 服务器,具体取决于版本。你会在这里找到更多信息:http: //dev.mysql.com/doc/refman/5.1/en/query-log.html

注意:记录查询对性能有重要影响,所以我不建议在生产服务器上这样做。

于 2013-08-23T15:38:41.640 回答