Search code examples
phporacleora-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

but the connection doesn't result in any errors and the DB table does exist and it is not empty.

Any ideas??? Thank you :).


Solution

  • 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)
    3. You may need to add the owner to the table name e.g. select * from DB_USER.mantis_bug_table (See Justin Cave's answer regarding SYNONYMs if you don't want qualify the tablename)
    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'