2011-04-20 41 views
0

我在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(); 
+0

接受最近的問題。 – hsz 2011-04-20 10:05:26

+0

請勿發佈您的用戶名和密碼... – rsplak 2011-04-20 10:06:20

+0

請選擇您的代碼,然後在提問時單擊{}圖標。這將格式化代碼。 – 2011-04-20 10:06:51

回答

0

您沒有適當的錯誤處理。 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()); 

?> 
+0

非常感謝你! – 2011-04-20 10:51:52

+0

如果您發現某人真正有用的答案,您需要接受此答案。您可以通過按下答案左上角的V圖標(使其變爲綠色)來做到這一點。 (根據票數)。 – 2011-04-20 11:02:04

+0

我現在怎麼寫輸出到一個文本文件,使它看起來不錯? 謝謝 – 2011-04-20 11:31:15

3

什麼你真的想要嗎? 您必須描述問題,否則沒有人可以幫助您...

+0

,這是一個評論,而不是一個鼻! – CloudyMarble 2011-04-20 10:10:46

+0

我沒有權利到處發表評論:S – KillerX 2011-04-20 10:12:47

+0

然後你不應該評論:-) – 2011-04-20 10:15:54

0

除了已經提到的,對於你的第二個結果的錯誤處理,您可能希望確保$ COUNT2是在在$ RESULT2返回的行數,而不是第一個結果集($結果)

$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($result2);