2010-10-27 77 views
0

當我嘗試此查詢:我是否連接到Oracle?

$query = "SELECT * FROM user_objects WHERE object_type = 'TABLE'"; 

...我得到一個空的結果集。

我已經使用error_reporting()設置爲E_ALL,所以我會假設,如果沒有正確連接,我會得到一個錯誤,對吧?

我正在使用一個上級給予我的類,它們用於一切,所以它應該工作。

如果您需要該代碼,請告訴我。

謝謝你們可以給我的任何幫助:)。

編輯

這裏是正在執行的實際查詢功能:

/** 
    * Query the database and store the result. If the query is a select it returns the number of rows 
    * fetched. 
    * 
    * Example: 
    * <code> 
    * $query = "SELECT * FROM tablename"; 
    * if($sql->query($query)){ 
    * while($sql->fetch()){ 
    *  foreach($sql->results as $a=>$b){ 
    *  print "$a: $b<br>"; 
    *  } 
    *  print "<hr>"; 
    * } 
    * }else{ 
    * print "No results"; 
    * } 
    * 
    * </code> 
    * 
    * @param SQL*Plus query statement 
    * @access public 
    * @return int 
    */ 
    function query($query_statement){ 
     if($_SESSION['TESTING']==1 && $_SESSION){ 
     $_SESSION['queries'][] = $query_statement; 
     $_SESSION['Total_queries'] = count($_SESSION['queries']); 
     } 
    $parse_result = $this->execute($query_statement); 
    if($parse_result == 0){ 
     return 0; 
    }else{ 
     if($this->_queryresult){ 
     oci_free_statement($this->_queryresult); 
     } 
     $this->results=array(); 
     $this->_queryresult = $parse_result; 
     $this->resultscount = oci_num_rows($this->_queryresult); 
     if(!$this->resultscount) 
     return 0; 
     else 
     return $this->resultscount; 
    } 
    } 
+0

代碼總是很有用:) oci_error函數應該提供更多的細節。 – JTP 2010-10-27 14:16:48

+0

oci_error()似乎沒有輸出任何東西:(。 – Will 2010-10-27 14:47:46

+0

至於oracle類的代碼,我不太瞭解它,以免泄漏安全漏洞等。:(我將添加查詢函數雖然 – Will 2010-10-27 14:48:31

回答

0

你可能想確保你顯示的錯誤,您可以強制一個檢查。在嘗試查詢之前,您還可以檢查connect語句的返回值。

0

您是否嘗試過使用相同的連接信息(用戶名/密碼)在SQL * Plus中運行查詢?也許你的用戶沒有任何表格對象。

+0

如果我通過Oracle SQL Developer運行它,那麼這個查詢似乎工作得很好。 :S – Will 2010-10-27 14:42:59