I have a database class that creates a database instance upon page load which in itself creates a database connection as such:
class database{
var $connection;
/* Class constructor */
function database(){
/* Make connection to database */
$this->connection = mysql_connect(DB_SERVER, DB_USER, DB_PASS) or die(mysql_error());
mysql_select_db(DB_NAME, $this->connection) or die(mysql_error());
Within this class I have a function that queries the database using the above connection like this:
function query($query){
return mysql_query($query, $this->connection);
}
This works properly if I use this query function once in my php, but the second I put this query function call into a loop all but the first instance of the query function call return a null result set. Here is an example of the loop code that is not working:
$chartSQL = "CALL RESEARCH.INTRA_DAY_PRICE('".$row['TICKER_I']."', 7)";
$result = $database->query($chartSQL);
Could this have something to do with the fact that I am querying a MySQL routine and not a simple select statement? Note that the routine "INTRA_DAY_PRICE" is a select statement using the supplied argument. Could it maybe be that I am using the same connection in a loop and the connection is simply in use during each consecutive call, thus the null result set?
Edit: Here is the whole loop:
$search_term = sr_addslashes($_GET['search']);
$sql = "SELECT DISTINCT t.TICKER_I, t.TICKER_C, t.TICKER_N, cpv.CURRENT_PRICE_A, cpv.MARKET_CAP, cpv.DA\
YS_CHANGE_A FROM ".DB_NAME.".TICKER_MyISAM t INNER JOIN ".DB_NAME.".CURRENT_PRICE_V cpv ON t.TICKER_I = cpv.TICKER\
_I WHERE t.INTEREST_F = 1 AND (MATCH(t.TICKER_C, t.TICKER_N) AGAINST('".$search_term."' IN BOOLEAN MODE) OR t.TICK\
ER_C = '".$search_term."' OR t.TICKER_N = '".$search_term."') LIMIT 20";
$results = $database->query($sql);
while($row = mysql_fetch_array($results)){
//Chart
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load('visualization', '1', {packages: ['annotatedtimeline']});
function drawVisualization() {
var data = new google.visualization.DataTable();
data.addColumn('date', 'Date');
data.addColumn('number', '<?php echo $row['TICKER_C']; ?>');
data.addRows([
<?php
$chartSQL = "CALL RESEARCH.INTRA_DAY_PRICE('".$row['TICKER_I']."', 7)";
$result = $database->query($chartSQL);
while($chartRow = mysql_fetch_array($result)){
echo $chartRow['FORMATTED'];
}
echo "null]);";
?>
var annotatedtimeline = new google.visualization.AnnotatedTimeLine(document.getElementById('chart_d\
iv_<?php echo $count; ?>'));
annotatedtimeline.draw(data, {'scaleType': 'maximized', 'displayRangeSelector': false, 'displayZoom\
Buttons': false});
}
google.setOnLoadCallback(drawVisualization);
</script>
<div id="chart_div_<?php echo $count; ?>" class="chart_div"></div>
<?php
// End Chart
}