Php 为什么我的mysql\u fetch\u数组或mysql\u fetch\u assoc不工作
我想把mysql查询的结果变成一个文本,目前当我输入mysql\u num\u字段和mysql\u num\u行时,它可以工作,但它不能工作mysql\u fetch\u数组或mysql\u fetch\u assoc,这是真正的要求。。谁能告诉我这个代码有什么问题吗Php 为什么我的mysql\u fetch\u数组或mysql\u fetch\u assoc不工作,php,mysql,Php,Mysql,我想把mysql查询的结果变成一个文本,目前当我输入mysql\u num\u字段和mysql\u num\u行时,它可以工作,但它不能工作mysql\u fetch\u数组或mysql\u fetch\u assoc,这是真正的要求。。谁能告诉我这个代码有什么问题吗 $query = "CALL create_report($ID, '$startDate', '$endDate', $endlmt, $position);"; $Localcon = $this->getCo
$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 = "-------------\n";
fwrite($fh, $stringData);
$stringData = mysql_fetch_array($result);
fwrite($fh, $stringData);
fclose($fh);
编辑代码
$stringData_2 = mysql_fetch_array($result);
foreach ($stringData_2 as $string) {
$stringData = "----------------\n";
fwrite($fh, $stringData);
fwrite($fh, $string);
}
问题是返回一个数组,而需要一个字符串。以下是代码产生的错误:
fwrite() expects parameter 2 to be string, array given in ...
fwrite的2个参数,$stringData
,必须是字符串
根据您正在尝试做的事情,您可以从尝试类似的事情开始,然后尝试其他替代方案:
...
foreach($result as $str) {
fwrite($fh, $str);
}
...
旁注:
$result=mysql\u query($query,$Localcon)或die(mysql\u error($Localcon))代码>打印($result)代码>并确保它包含您的想法。然后通过传递单个简单字符串来检查fwrite
是否有效。