Php
將 SQL 查詢輸出為變數 PHP
我有一個 PHP 腳本,它連接到我的一個 SQL 數據庫並執行一個選擇命令。然後我試圖查看命令的輸出,但是當我將結果回顯到文件時,我得到“資源 id #5”,而不是我期望的路徑。誰能告訴我哪裡出錯了,我懷疑是查詢或結果變數,但我對 php 很陌生。
$connection = mysql_connect("127.0.0.1", "user", "password"); if(!$connection) { system("echo 'ERROR! Unable to connect to MYSQL' >> /Reports/sqlerror"); } $dbselect = mysql_select_db("mydatabase"); $query = "select p.path from path as p join file as f on p.pathid=f.pathid where f.filename like '$xfilename' and p.path like '/Data/original%'"; $result = mysql_query($query); mysql_close($connection); system("echo '$result' >> /Report/sqloutput");
找到了答案。需要使用 mysql_fetch 如下。
$query = mysql_query (“select p.path from path as p join file as f on p.pathid=f.pathid where f.filename like ‘$xfilename’ and p.path like ‘/Data/original%’”);
$ result = mysql_fetch_row( $ 詢問); 系統(“迴聲’$結果**
$$ 0 $$**’ >> /Report/sqloutput");