2014-12-03 33 views
-4

我想MySQL查詢到文本的結果,目前它的作品當我鍵入mysql_num_fieldsmysql_num_rows,但它不工作mysql_fetch_arraymysql_fetch_assoc這是真正的需求..任何人可以請你告訴我什麼不對的代碼爲什麼犯規我mysql_fetch_array或mysql_fetch_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); 
    } 
+0

'$結果= mysql_query($ query,$ Localcon)或者死(mysql_error($ Localcon));' – 2014-12-03 04:08:28

+0

[PHP 5.5.x中的棄用功能 - ext/mysql deprecation](http://php.net/manual/migration55.deprecated。 php#migration55.deprecated.mysql) – Phil 2014-12-03 04:13:52

回答

2

問題是mysql_fetch_array返回一個數組,而fwrite期待一個字符串。這裏是你的代碼產生錯誤:

fwrite() expects parameter 2 to be string, array given in ... 

FWRITE,$stringData的2 PARAM,必須是一個字符串。

取決於你正在嘗試做的,你可能會想這樣的事情開始,然後玩弄其他的替代品:

... 
foreach($result as $str) { 
    fwrite($fh, $str); 
} 
... 

旁註:Why shouldn't I use mysql_* functions in PHP?

+0

感謝您的回覆!! ..生病檢查答案 – 2014-12-03 04:40:48

+0

很高興幫助:) – 2014-12-03 04:41:17

+0

它沒有工作,,,沒有打印:) – 2014-12-03 06:07:36

相關問題