i want to get the result of mysql query into a text, currently it works when i type mysql_num_fields and mysql_num_rows, but it does not work mysql_fetch_array or mysql_fetch_assoc which is the genuine requirement.. can anybody kindly tell me what wrong with this code
$query = "CALL create_report($ID, '$startDate', '$endDate', $endlmt, $position);";
$Localcon = $this->getConnection();
$result = mysql_query($query, $Localcon);
//$debug = mysql_num_rows($result);
$myFile = "debug.txt";
$fh = fopen($myFile, 'w') or die("can't open file");
$stringData = "-------------
";
fwrite($fh, $stringData);
$stringData = mysql_fetch_array($result);
fwrite($fh, $stringData);
fclose($fh);
edited code
$stringData_2 = mysql_fetch_array($result);
foreach ($stringData_2 as $string) {
$stringData = "----------------
";
fwrite($fh, $stringData);
fwrite($fh, $string);
}
The problem is mysql_fetch_array returns an array, while fwrite is expecting a string. Here is the error your code produces:
fwrite() expects parameter 2 to be string, array given in ...
The 2 param of fwrite, $stringData
, needs to be a string.
Depending on what you are trying to do, you might start by trying something like this, then play around with other alternatives:
...
foreach($result as $str) {
fwrite($fh, $str);
}
...