Php 需要查询数据库帮助的脚本

Php 需要查询数据库帮助的脚本,php,Php,我有以下php代码: $host="localhost"; // Host name $username="***"; // username $password="***"; // password $db_name="***"; // Database name //$rc_profile_table="rc_profile_table"; // Table name //$rc_profile_relation_table="rc_profile_relation_table"; // T

我有以下php代码:

$host="localhost"; // Host name
$username="***"; // username
$password="***"; // password
$db_name="***"; // Database name
//$rc_profile_table="rc_profile_table"; // Table name
//$rc_profile_relation_table="rc_profile_relation_table"; // Table name


mysql_connect("$host", "$username", "$password");
mysql_select_db("$db_name");

$sql="SELECT created_at FROM rc_profile_table where created_at > 2011-04-19 08:00:00";
$result=mysql_query($sql);
$count=mysql_num_rows($result);

$sql="SELECT created_at FROM rc_profile_relation_table where created_at > 2011-04-19 08:00:00";
$result2=mysql_query($sql);
$count2=mysql_num_rows($result);

 mysql_close();

你到底想做什么?
你必须描述这个问题,否则没有人能帮你…

你到底想做什么?
您必须描述问题,否则没有人可以帮助您……

您没有正确的错误处理。php提供的mysql功能有一个内置函数,可以在屏幕上输出错误。 这样会更好:

<?php
$host="localhost"; // Host name 
$username="***"; // username 
$password="***"; // password 
$db_name="***"; //db name

$connection = mysql_connect($host, $username, $password) or die("Could not connect to the database: " . mysql_error()); 
mysql_select_db($db_name, $connection) or die("Could not select database: " . mysql_error());

$sql = "SELECT `created_at` FROM `rc_profile_table` WHERE `created_at` > '2011-04-19 08:00:00'"; 
$result = mysql_query($sql) or die("Could not execute query: " . $sql . "ERROR: " . mysql_error()); 
$count = mysql_num_rows($result);

mysql_close($connection) or die(mysql_error());

?>

您没有正确的错误处理。php提供的mysql功能有一个内置函数,可以在屏幕上输出错误。
这样会更好:

<?php
$host="localhost"; // Host name 
$username="***"; // username 
$password="***"; // password 
$db_name="***"; //db name

$connection = mysql_connect($host, $username, $password) or die("Could not connect to the database: " . mysql_error()); 
mysql_select_db($db_name, $connection) or die("Could not select database: " . mysql_error());

$sql = "SELECT `created_at` FROM `rc_profile_table` WHERE `created_at` > '2011-04-19 08:00:00'"; 
$result = mysql_query($sql) or die("Could not execute query: " . $sql . "ERROR: " . mysql_error()); 
$count = mysql_num_rows($result);

mysql_close($connection) or die(mysql_error());

?>

除了前面提到的错误处理之外,对于第二个结果集,您可能希望确保$count2是$result2中返回的行数,而不是第一个结果集($result)中返回的行数


除了前面提到的错误处理之外,对于第二个结果集,您可能希望确保$count2是$result2中返回的行数,而不是第一个结果集($result)中返回的行数



接受您最近的问题。不要发布您的用户名和密码…当您提出问题时,请选择您的代码并单击{}图标。这将格式化代码。是的,这就是代码。你希望它做什么?接受你最近的问题。不要发布你的用户名和密码…当你提问时,请选择你的代码并单击{}图标。这将格式化代码。是的,这就是代码。你希望它做什么?这是一个评论,而不是一个naswer!那么你不应该评论:-)这是评论而不是回答!然后你不应该评论:-)如果你发现某人的答案真的很有用,你需要接受这一点。您可以通过按下答案左上角的V图标(使其变为绿色)来完成此操作。(在有投票权的数字下)。我现在如何将输出写入文本文件以使其看起来美观?感谢您使用.txt文件或网页?谢谢我对其进行了排序,我想在数据库上运行一些查询,以获取一些统计信息,并以文本文件的形式发送给客户。谢谢大家!如果你找到一个真正有用的人的答案,你需要接受这一点。您可以通过按下答案左上角的V图标(使其变为绿色)来完成此操作。(在有投票权的数字下)。我现在如何将输出写入文本文件以使其看起来美观?感谢您使用.txt文件或网页?谢谢我对其进行了排序,我想在数据库上运行一些查询,以获取一些统计信息,并以文本文件的形式发送给客户。谢谢大家!