Jump to content

script for query a db help needed


helloise

Recommended Posts

i have the following code in php:

<?php

error_reporting (E_ALL);

 

$host="localhost"; // Host name

$username="elemental"; // username

$password="rclogin"; // password

$db_name="traffic2"; // 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();

 

?>

 

am i on the right path please?

thank you

Link to comment
https://forums.phpfreaks.com/topic/234239-script-for-query-a-db-help-needed/
Share on other sites

Your going the right way, except for a couple of things: your timestamp value in the query string should be enclosed in single quotes; you should have error capture on your connection and query stings and you are using 2 queries where 1 would do.

 

other than that looks spot on, It would be better if you would continue the verbose commenting aswell.

i made some changes and it looks like this now:

<?php
error_reporting (E_ALL);

$host="localhost"; // Host name
$username="elemental"; // username
$password="rclogin"; // password
$db_name="traffic2"; // 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")or die("Could not connect to the database: " . mysql_error()) ;
mysql_select_db("$db_name") 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);
$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)or die("Could not execute query: " . $sql . "ERROR: " . mysql_error()) ;
$count2=mysql_num_rows($result)or die(mysql_error()) ;

mysql_close();
?>

 

how can i write some output to a text file to make it look nice?

thanks

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.