|
Reg database connection for interactive financial charts |
Posted by Pankaj Arya on Oct-01-2012 21:46 |
|
Regarding the Post , http://www.chartdir.com/forum/download_thread.php?site=chartdir&bn=chartdir_support&thread=1293652862&new_thread=1
Hi Peter,
as you have mentioned. i have created database in sql , i am able to connect to database also. and wrote the following code
function generateRandomData($ticker, $startDate, $endDate, $resolution) {
global $timeStamps, $volData, $highData, $lowData, $openData, $closeData;
$dbhost = "localhost";
$dbuser = "EodData";
$dbpass = "mydbpassword";
$dbname = "EodDataDB";
if(!@mysql_connect($dbhost,$dbuser,$dbpass)) {
echo "<br><br><center>There seems to be some technical problem(s) at the moment, we are trying it fix it. Please visit later.<br>Team.</center>";
die();
} else {
//echo "Connection to the databse is successful<br>" ;
mysql_select_db($dbname);// or report();
// paste Your code below this //
$data = mysql_query("SELECT *
FROM `nse_cash_eod_data`
WHERE SYMBOL = '$ticker'
LIMIT $startDate , $endDate" )
or die(mysql_error());
while($info = mysql_fetch_array( $data ))
{
$date = new DateTime($info['TIMESTAMP'];);
$unix = $date->getTimestamp();
$timeStamps[]=chartTime2($unix);
$openData[]=$info['OPEN'];
$highData[] =$info['HIGH'];
$lowData[] =$info['LOW'];
$closeData[]=$info['CLOSE'];
$volData[] =$info['TTQTY'];
} // end while
} //end else
} // end generateRandomData
But still i am not able to plot the charts.
i am using php version 5.3.17 on windows server.
Looks like i am quite near to get my charts work
Thanks in Advance
Pankaj Arya |
Re: Reg database connection for interactive financial charts |
Posted by Peter Kwan on Oct-02-2012 02:41 |
|
Hi Pankaj,
You mentioned you can "connect to database". But can you read data from the database with your SQL query?
Your SQL query looks strange to me (or I may not understand your query). For example, you use the "LIMIT" with dates in your query, but the LIMIT is supposed to accept row numbers, not date/time. (Please refer to MySQL documentation for details of their SQL syntax.) Usually, the WHERE clause is used to select the data you want, and the LIMIT clause is to use to limit the number of rows returned (but not to select what is returned).
There is a forum thread below that includes a workable SQL statement. Note that the SQL for every database is different, because every database can have a different schema. You would need to adapt it to your own database.
http://www.chartdir.com/forum/download_thread.php?bn=chartdir_support&thread=1262434685#N1265018420
Hope this can help.
Regards
Peter Kwan |
|