2015-01-08 3 views
1

연결하려는 Oracle 데이터베이스가 있습니다. 나는 다음과 같은 코드를하려고 몇 가지 이유를 들어 PHP에서 Oracle 데이터베이스에 연결

: 나는 위의 코드를하려고하면

<?php 
    include "header.php"; 
    // simply attempt to connect to the database 
    /* If you are connecting to the Oracle database, the credentials are as follows: 
    * Username: ******** 
    * Password: ******** 
    * Hostname: ********** 
    * Port: 1521 
    * Service name: *********** 
    */ 
    $oracleConnect = true; 
    if ($oracleConnect) 
    { 
     echo 'Attempting connection...<br>'; 
     $connection = null; 
     try 
     { 
      $connection = oci_connect('user', 
       'pass', 
       '[email protected]//hostname:1521/dbname'); 
     } 
     catch (Exception $e) 
     { 
      echo $e->getMessage(); 
     } 
     if (!$connection) 
     { 
      echo '<p>Something is wrong.</p>'; 
      $e = oci_error(); 
      trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR); 
     } 
     // if the connection has been established 
     else 
     { 
      // tell the user and close it (this is a test) 
      echo 'Connection established!!'; 
      oci_close($connection); 
     } 
    } 
    else 
    { 
     $connection = new mysqli('host', 'user', 'password', 'database'); 
     echo ($connection) ? 'Database connection successful!' : 'Could not connect.'; 
    } 
    include "footer.php"; 
?> 

, 나는 "... 시도 접속"를 얻을 인쇄 할 수 있지만, 아무것도. 그것은 관계없이 다른 것을 인쇄하기로되어 있습니다. 무엇이 잘못 될 수 있습니까?

+1

프로세스가 입력되었는지 확인하기 위해 "try"에서 뭔가를 울립니다. '

답변

0

문제는 연결 문자열의 [email protected] 부분이라고 생각합니다. 난 그게 필요하다고 생각 oci_connect 사용자 이름 매개 변수가 있습니다. 나는, 필자 전에 PHP에서 오라클을 사용한 적이 잘못 될 수 있지만, the docs on oci connections는 것을 나타냅니다 보일 수있을 것입니다 : 내가 그래서 당신의 시도/캐치하지 않는 한 쓸모가 말할 수있는

To use the Easy Connect naming method, PHP must be linked with Oracle 10g or greater Client libraries. The Easy Connect string for Oracle 10g is of the form: [//]host_name[:port][/service_name]. From Oracle 11g, the syntax is: [//]host_name[:port][/service_name][:server_type][/instance_name]. Service names can be found by running the Oracle utility lsnrctl status on the database server machine.

는 또한 oci_connect이 지금까지 예외를 throw하지 않습니다 false을 반환 할 때 자신의 것을 던질 계획을 세웠습니다.

+0

좋아, 그래서'user @'부분과 try/catch 블록을 꺼 냈고, 여전히 작동하지 않는다! 테스트 사이트는 다음과 같습니다. http://dinotator.biokdd.org/ResearchProject/dbConnect.php –

+1

display_errors를 @JayBlanchard로 설정하고 주석이 있는지 확인하고 연결이없는 경우에도 참조하십시오. print_r ($ e)'형식을 사용하는 대신 ... 뭔가 잘못되었을 수도 있습니다. 왜냐하면 결코 바닥 글에 포함시키기 위해 그것을 만들지 않기 때문입니다. 즉, 처리를 멈추는 오류가 있음을 의미합니다. 그리고 그 곳이 가장 가능성이 큽니다. – prodigitalson

+0

oci_connect()가 "정의되지 않음"입니다! '치명적인 오류 : 정의되지 않은 함수를 호출합니다. /home1/biokddor/public_html/dinotator/reesearchProject/dbConnect.php on line 17' –

관련 문제