为什么我会收到此错误以及如何修复它?

发布于 2025-01-08 05:18:33 字数 541 浏览 0 评论 0原文

我编写了一个 PHP 脚本来从 Oracle 数据库中提取查询并将结果写入 csv 文件。我正在使用 Zend Framework 连接到数据库。我知道凭据是正确的,因为我可以使用 SQLPlus 通过终端进行连接。

这是错误:

Zend_Db_Adapter_Exception: SQLSTATE[HY000]: pdo_oci_handle_factory: ORA-12514: TNS:listener 目前不知道连接描述符中请求的服务 (/home/http/php-5.3.3/ext/pdo_oci/ oci_driver.c:579) 在/opt/http/Zend/ZendFramework-1.10.3/library/Zend/Db/Adapter/Pdo/Abstract.php on line 144

我尝试过进行研究,但没有可靠的解决方案。我确实读到它可能与 tnsnames.ora 关联,但我在服务器上找不到该文件。我之前在其他项目中使用过 Zend,没有任何问题。

仅供参考:我没有root权限,所以我不能在服务器上做太多的事情。

您有什么建议?

I have written a PHP script to pull a query from an Oracle database and write results to a csv file. I am using Zend Framework to get connected to the database. I know the credentials are correct as I am able to connect through terminal using SQLPlus.

This is the error:

Zend_Db_Adapter_Exception: SQLSTATE[HY000]: pdo_oci_handle_factory: ORA-12514: TNS:listener does not currently know of service requested in connect descriptor (/home/http/php-5.3.3/ext/pdo_oci/oci_driver.c:579) in /opt/http/Zend/ZendFramework-1.10.3/library/Zend/Db/Adapter/Pdo/Abstract.php on line 144

I have tried to do research, but no solid solutions. I did read that it could be associated with the tnsnames.ora but I couldn't find that file on the server. I have used Zend before in other projects without any issues.

FYI: I do not have root, so I can't do much magic on the server.

What are your suggestions?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

琴流音 2025-01-15 05:18:33

您需要在 $ORACLE_HOME/network/admin 文件夹中创建一个名为 tnsnames.ora 的文件,并将您的 SID 放入其中。

或者,如果您无法创建 tnsnames.ora,请尝试使用以下语法设置数据库配置:

$config = new Zend_Config(
array(
'database' => array(
'adapter' => 'oracle',
'params' => array(
    'dbname'=> '(DESCRIPTION =(ADDRESS = (PROTOCOL = TCP)(HOST = hostname.domain.tld)(PORT = 1521))(CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = service_name)))',
    'username' => 'dev',
    'password' => 'pwd')
    )
)
);
$db = Zend_Db::factory($config->database);
Zend_Db_Table::setDefaultAdapter($db);

尽管最好使用数据库配置创建 tnsnames.ora。

You need to create a file called tnsnames.ora in your $ORACLE_HOME/network/admin folder and put in it your SID .

or if you can't create your tnsnames.ora, try setting your DB config using this syntax :

$config = new Zend_Config(
array(
'database' => array(
'adapter' => 'oracle',
'params' => array(
    'dbname'=> '(DESCRIPTION =(ADDRESS = (PROTOCOL = TCP)(HOST = hostname.domain.tld)(PORT = 1521))(CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = service_name)))',
    'username' => 'dev',
    'password' => 'pwd')
    )
)
);
$db = Zend_Db::factory($config->database);
Zend_Db_Table::setDefaultAdapter($db);

Althought its better to create tnsnames.ora with your DB config.

提笔书几行 2025-01-15 05:18:33

对于那些不使用 Zend Framework,但有类似问题的人,可以在 http://docs.php.net/manual/en/ref.pdo-oci.php#64756

$tns = "  
(DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = yourip)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = orcl)
    )
  )
       ";
$db_username = "youname";
$db_password = "yourpassword";
try{
    $conn = new PDO("oci:dbname=".$tns,$db_username,$db_password);
}catch(PDOException $e){
    echo ($e->getMessage());
}

如果您使用 SID 进行连接,请更改

(SERVICE_NAME = orcl) 

(SID = yourSid) 

For those not using Zend Framework, but having similar issue, a solution to this problem can be found on http://docs.php.net/manual/en/ref.pdo-oci.php#64756

$tns = "  
(DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = yourip)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = orcl)
    )
  )
       ";
$db_username = "youname";
$db_password = "yourpassword";
try{
    $conn = new PDO("oci:dbname=".$tns,$db_username,$db_password);
}catch(PDOException $e){
    echo ($e->getMessage());
}

If you're using SID to connect, change

(SERVICE_NAME = orcl) 

to

(SID = yourSid) 
叫思念不要吵 2025-01-15 05:18:33

这是来自 Oracle 的常见错误消息,与 zend 甚至 php 无关。我通常在 SQLDeveloper 或 Toad 中收到此消息。检查 tnsnames.ora、listener.ora、sqlnet.ora、日志文件等并尝试与客户端应用程序连接。 (如果还是不行,可以向管理员反馈)

That's a common errormessage from Oracle, there is nothing to do with zend or even php. I usually get this message in SQLDeveloper or Toad. Check the tnsnames.ora, listener.ora, sqlnet.ora, log files etc. and try to connect with a client app. (if it isn't working, you can report it to the admins)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文