Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/265.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/react-native/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 为什么我的mysql\u fetch\u数组或mysql\u fetch\u assoc不工作_Php_Mysql - Fatal编程技术网

Php 为什么我的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

我想把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->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
是否有效。