Forum Moderators: coopster

Message Too Old, No Replies

mysqli error

         

jackvull

5:28 pm on Apr 12, 2011 (gmt 0)

10+ Year Member



2 parts to this.
Firstly I am getting a command out of sync error.
I can only seem to fix this by using:
while($mysqli->next_result()) $mysqli->store_result();
Why do I have to so that to get this to work?

Secondly,
The 1st SQL statement has 222 rows. I have echoed out the names correctly. Mysteriously it only goes through the 2nd loop in the data about 82 (echo $cti;) times and stops.
Any ideas on what could be wrong with the code?
I typed out some echo statements to debug it and it looks like after row 82 of 226 it just exists the for loop, doesn;t even go back into it.
I have put the recordset in ascending, descending, limit of 100, etc. and it always stops at record 82!
I also changed the execution time in apache and php and that didn't help.


require_once ('jpgraph-3.5.0b1/src/jpgraph.php');
require_once ('jpgraph-3.5.0b1/src/jpgraph_line.php');

//db connect
$mysqli = new mysqli("localhost","root","aaa","aaa");
if (mysqli_connect_errno()) {
printf("Connection failed: %s\n", mysqli_connect_error());
exit();
}

//variables
$ratio = array();
$mean = array();
$meanupper = array();
$meanlower = array();
$muTwoSD = array();
$mlTwoSD = array();
$datay1 = array();
$datay2 = array();
$datay3 = array();
$datay4 = array();
$datay5 = array();
$datay6 = array();
$arr_cmp1 = array();
$arr_cmp2= array();

//processing code below
//$ins = $mysqli->query("INSERT INTO sproc_run_history (stamptime,calledFrom) VALUES (NOW(),'mkimages.php')") or die($mysqli->error);
//while($mysqli->next_result()) $mysqli->store_result();
//mysqli_free_result($ins);

$rs = $mysqli->query("SELECT Company1, Company2 FROM results ORDER BY Company1") or die($mysqli->error);
//store the $rs into an array here?
while ($row = $rs->fetch_object()) {
$arr_cmp1[]= $row->Company1;
$arr_cmp2[] = $row->Company2;
}
while($mysqli->next_result()) $mysqli->store_result();
mysqli_free_result($rs);

$ct = count($arr_cmp1);

for ($cti=1; $cti<$ct; $cti++) {
$cmp1 = $arr_cmp1[$cti];
$cmp2 = $arr_cmp2[$cti];
unset($ratio,$mean,$meanupper,$meanlower,$muTwoSD,$mlTwoSD,$arr_);
echo $cti."<br />";
$result = $mysqli->query("CALL GetGraph('".$cmp1."','".$cmp2."')") or die($mysqli->error);
while ($row_sp = $result->fetch_object()) {
$ratio[] = array($row_sp->Ratio);
$mean[] = array($row_sp->Mean);
$meanupper[] = array($row_sp->MeanUpper);
$meanlower[] = array($row_sp->MeanLower);
$muTwoSD[] = array($row_sp->MUTwoSD);
$mlTwoSD[] = array($row_sp->MLTwoSD);
}
while($mysqli->next_result()) $mysqli->store_result();
mysqli_free_result($result);

/////////////////
//LOAD DATA FOR GRAPHS
/////////////////
unset($datay1,$datay2,$datay3,$datay4,$datay5,$datay6);

for($i = 0; $i < count($mean); $i++) {
$datay1[$i] = $ratio[$i][0];
$datay2[$i] = $meanlower[$i][0];
$datay3[$i] = $mean[$i][0];
$datay4[$i] = $meanupper[$i][0];
$datay5[$i] = $muTwoSD[$i][0];
$datay6[$i] = $mlTwoSD[$i][0];
}

// Setup the graph
$graph = new Graph(600,300);
$graph->SetScale("textlin");
$theme_class=new UniversalTheme;
$graph->SetTheme($theme_class);
$graph->img->SetAntiAliasing(false);
$graph->title->Set($cmp1.' / '.$cmp2);
$graph->SetBox(false);
$graph->img->SetAntiAliasing();
$graph->yaxis->HideZeroLabel();
$graph->yaxis->HideLine(false);
$graph->yaxis->HideTicks(false,false);
$graph->xgrid->Show();
$graph->xgrid->SetLineStyle("solid");
$graph->xaxis->SetTickLabels(array('1','2','3','4'));
$graph->xgrid->SetColor('#E3E3E3');

// Create the first line
$p1 = new LinePlot($datay1);
$graph->Add($p1);
$p1->SetColor("#6495ED");
//$p1->SetLegend('Line 1');

// Create the second line
$p2 = new LinePlot($datay2);
$graph->Add($p2);
$p2->SetColor("#FFAA00");

// Create the third line
$p3 = new LinePlot($datay3);
$graph->Add($p3);
$p3->SetColor("#000000");

// Create the 4thline
$p4 = new LinePlot($datay4);
$graph->Add($p4);
$p4->SetColor("#FFAA00");
// Create the 5thline
$p5 = new LinePlot($datay5);
$graph->Add($p5);
$p5->SetColor("#CC0000");

// Create the 6thline
$p6 = new LinePlot($datay6);
$graph->Add($p6);
$p6->SetColor("#CC0000");

$graph->legend->SetFrameWeight(1);
// Output line
$cmp1 = str_replace(".L", "", $cmp1);
$cmp2 = str_replace(".L", "", $cmp2);
$name = $cmp1."-".$cmp2;
$graph->Stroke('images/'.$name.'.jpg');
//$graph->Stroke();

}//end 1st while
$mysqli->close();

SteveWh

4:06 pm on Apr 13, 2011 (gmt 0)

10+ Year Member



I'd suggest looking at the examples on relevant pages linked from [us.php.net...] . Look up the various functions you're using, and examine the example code.

I may be somewhat out of my depth trying to analyze your code, but it looks to me as though you are mixing functions that aren't intended to be used together. For example, [us.php.net...] says that next_result() is intended to be used after multi_query(), which isn't what you're using.

The object-oriented mysqli methods should be easier to troubleshoot. Have a look at the example code at the Object oriented style code at [us.php.net...] , and see if that might be adapted to your purpose.

Be consistent in use of object-oriented style (better) or procedural style, using the examples as a guide to which functions are intended to be used together.

Without going over your code carefully, I can only say that it intuitively doesn't look right. If someone else can identify more specific issues, take their advice instead :)