简体   繁体   English

Oracle SELECT语句不起作用 - ORA-00942

[英]Oracle SELECT statement not working - ORA-00942

Hopefully a simple question. 希望是一个简单的问题。

    error_reporting(E_ALL);
    ini_set('display_errors', '1');
    $c = oci_connect('whatmyusrnameis', 'whatmypwdis', 'host');
    if ($c) {
            echo 'connection';

    }
    $s = oci_parse($c, 'select *  from mantis_bug_table');
    oci_execute($s);

The following results in 以下结果

Warning oci_execute(): ORA-00942: table or view does not exist 警告oci_execute(): ORA-00942: table or view does not exist

but the connection doesn't result in any errors and the DB table does exist and it is not empty. 但是连接不会导致任何错误,并且DB表确实存在并且它不是空的。

Any ideas??? 有任何想法吗??? Thank you :). 谢谢 :)。

Typically this has one of four possible problems 通常,这有四个可能的问题之一

  1. You're not connecting to the database you think you are (probably not the case) 您没有连接到您认为自己的数据库(可能不是这种情况)
  2. You don't have permission to the table (See Justin Cave's answer regarding Grant) 你没有表格的许可(参见Justin Cave关于格兰特的回答)
  3. You may need to add the owner to the table name eg select * from DB_USER.mantis_bug_table (See Justin Cave's answer regarding SYNONYMs if you don't want qualify the tablename) 您可能需要将所有者添加到表名中,例如select * from DB_USER.mantis_bug_table (如果您不想要限定表名,请参阅Justin Cave关于SYNONYM的答案)
  4. The table really doesn't exist perhaps a spelling error 该表确实不存在拼写错误

You can diagnose this by running the following 您可以通过运行以下命令来诊断它

SELECT * FROM ALL_TABLES WHERE UPPER(table_name) = 'MANTIS_BUG_TABLE'
  • What Oracle user owns the table? Oracle用户拥有哪些表?
  • Does the Oracle user that your PHP script connects as have access to this table? 您的PHP脚本连接的Oracle用户是否可以访问此表?
  • Is there a public or private synonym for the MANTIS_BUG_TABLE table? 是否有MANTIS_BUG_TABLE表的公共或私有同义词?

If the table is owned by some other user, you could try fully qualifying the table name 如果该表由其他某些用户拥有,则可以尝试完全限定表名

$s = oci_parse($c, 'select *  from owner_of_table.mantis_bug_table');

If the user your PHP script is using doesn't have access to the table, you'll need a DBA or the owner of the table to 如果您的PHP脚本使用的用户无权访问该表,则您需要DBA或该表的所有者

GRANT SELECT ON owner_of_table.mantis_bug_table
   TO whatmyusernameis;

If you have access to the table and fully qualifying the table name works but you don't want to have to fully qualify the table name every time, you can create a synonym 如果您有权访问该表并完全限定表名,但您不希望每次都完全限定表名,则可以创建同义词

CREATE [PUBLIC] SYNONYM mantis_bug_table
   FOR owner_of_table.mantis_bug_table

A public synonym allows all users with access to the table to reference it without using a fully qualified name. 公共同义词允许所有有权访问该表的用户在不使用完全限定名的情况下引用该表。 A private synonym allows just the owner of the synonym (ie whatmyusernameis) to reference the table without a fully qualified table name. 私有同义词只允许同义词的所有者(即whatmyusernameis)引用该表而没有完全限定的表名。

You should point scheme in connection string like: 你应该在连接字符串中指向scheme,如:

oci_connect('whatmyusrnameis', 'whatmypwdis', 'host/**YOUR_DB**');

Look at http://www.php.net/manual/en/function.oci-connect.php in section connection_string 请查看connection_string部分中的http://www.php.net/manual/en/function.oci-connect.php

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM