Welcome Guest, Not a member yet? Register   Sign In
getting message: oci_execute(): ORA-00942: table or view does not exist
#1

hi all,

I am very new to Codeigniter, I am creating a Form to get Oracle's default HR schema table departments data but it showing error:

Message: oci_execute(): ORA-00942: table or view does not exist

the same things working for MySQL database, with just change 2 lines in model, my model file is as below:

Quote:<?php
//public $db;

class dep_models extends CI_Model{

function __construct()//model construct function
{
    parent::__construct();
    $this->oracle_db=$this->load->database('oracle',true); // oracle db
    //$this->db=$this->load->database('default',true); // mysql db
}

function getDept(){
   //return $this->oracle_db->get('departments')->result();
   $result=$this->oracle_db->get('departments'); // oracle db
   //$result=$this->db->get('departments'); // mysql db
   return $result;
}
}
?>

when un-comment lines with "mysql db" and simply refresh page, it works fine but for "oracle db" it is showing error but it seems connected successfully. 
please help as i am working on Oracle database.

regards
Reply
#2

This is wrong CodeIgniter CI_Model has no constructor so you cannot use 
PHP Code:
parent::__construct(); 

This is how it should be, see how the class name is ucfirst uppercase it also needs to be saved that way.
PHP Code:
class Dep_models extends CI_Model
{
 
   private $oracle_db;

 
   public function __construct() //model construct function
 
   {
 
       $this->oracle_db $this->load->database('oracle',true); // oracle db
 
   }

 
   public function getDept()
 
   {
 
       $query $this->oracle_db->get('departments')
 
                     ->result();

 
       return $query;
 
   }


Of course you would need to add error checking on all of your database code.
Use Google to search for what you need.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

(This post was last modified: 11-08-2018, 10:16 AM by php_rocs.)

@ahmed Haroon,

What does your config file look like?

Your hostname should be something along this line...

'hostname' => '123.345.456.21:1521/SSID',
Reply
#4

(11-08-2018, 10:05 AM)InsiteFX Wrote: This is wrong CodeIgniter CI_Model has no constructor so you cannot use 
PHP Code:
parent::__construct(); 

I admit I'm being pedantic here, but CI_Model does have a constructor. It is empty, but it's there. So you're right in the sense that making the call is pointless.
Reply
#5

(11-08-2018, 10:05 AM)InsiteFX Wrote: This is wrong CodeIgniter CI_Model has no constructor so you cannot use 
PHP Code:
parent::__construct(); 

This is how it should be, see how the class name is ucfirst uppercase it also needs to be saved that way.
PHP Code:
class Dep_models extends CI_Model
{
 
   private $oracle_db;

 
   public function __construct() //model construct function
 
   {
 
       $this->oracle_db $this->load->database('oracle',true); // oracle db
 
   }

 
   public function getDept()
 
   {
 
       $query $this->oracle_db->get('departments')
 
                     ->result();

 
       return $query;
 
   }


Of course you would need to add error checking on all of your database code.
Use Google to search for what you need.

thanks very much for reply and guidance. still getting same error, i am posting here code of files as below:

in Controller folder, file name Depts.php
PHP Code:
<?php
class Depts extends CI_Controller{
 
 function __construct(){
 
   parent::__construct();
 
   $this->load->model('dep_models');
 
 }
 
 function index(){
 
   $data['departments'] = $this->dep_models->getDept();
 
   $this->load->view('dep_view',$data);
 
 }
}
?>

in Model folder, Dep_Models.php
PHP Code:
<?php
class Dep_models extends CI_Model
{
 
   private $oracle_db;

 
   public function __construct() //model construct function
 
   {
 
       $this->oracle_db $this->load->database('oracle',true); // oracle db
 
   }

 
   public function getDept()
 
   {
 
       $query $this->oracle_db->get('departments')->result();

 
       return $query;
 
   }

?>

in config folder, file database.php
PHP Code:
$active_group 'oracle';
$query_builder TRUE;

$db['oracle'] = array(
 
   'dsn'   => '',
 
   'hostname' => '127.0.0.1:1521/orclpdb',
 
   //'hostname' => 'localhost',
 
   'username' => 'hr'
 
   'password' => 'hr',
 
   'database' => 'orclpdb',
 
   'dbdriver' => 'oci8',
 
   'dbprefix' => '',
 
   'pconnect' => FALSE,
 
   'db_debug' => (ENVIRONMENT !== 'production'),
 
   'cache_on' => FALSE,
 
   'cachedir' => '',
 
   'char_set' => 'utf8',
 
   'dbcollat' => 'utf8_general_ci',
 
   'swap_pre' => '',
 
   'encrypt' => FALSE,
 
   'compress' => FALSE,
 
   'stricton' => FALSE,
 
   'failover' => array(),
 
   'save_queries' => TRUE,
 
   'save_queries' => TRUE,
); 

Error:
Quote:A PHP Error was encountered
Severity: Warning

Message: oci_execute(): ORA-00942: table or view does not exist

Filename: oci8/oci8_driver.php

Line Number: 286

Backtrace:

File: C:\wamp64\www\myproject\application\models\dep_models.php
Line: 13
Function: get

File: C:\wamp64\www\myproject\application\controllers\Depts.php
Line: 8
Function: getDept

File: C:\wamp64\www\myproject\index.php
Line: 315
Function: require_once

------------------------------------------------------------------------------------------------------

A Database Error Occurred
Error Number: 942

ORA-00942: table or view does not exist

SELECT * FROM "departments"

Filename: C:/wamp64/www/myproject/system/database/DB_driver.php

Line Number: 691

if anything else, i can share because all are just Test / Practice files.
regards
Reply
#6

(11-08-2018, 10:12 AM)php_rocs Wrote: @ahmed Haroon,

What does your config file look like?

Your hostname should be something along this line...

'hostname' => '123.345.456.21:1521/SSID',

thanks for your reply, I have posted above my database.php entry for Oracle database.
regards
Reply
#7

Did you save your model with the first character upper case?

Dep_models.php
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#8

(11-09-2018, 04:45 AM)InsiteFX Wrote: Did you save your model with the first character upper case?

Dep_models.php

thank you Smile

No, I didn't...
Reply
#9

@ahmed Haroon,

Are you still getting an error message? Is it working for you now?
Reply
#10

(This post was last modified: 11-12-2018, 02:04 AM by Ahmed Haroon.)

thanks @php_rocs, i already have mentioned in my reply to @InsiteFX that getting same error (also posted program codes and complete errors), now I can test anything on coming Monday if I someone guide me.
I have following environment ( on VM )
Win 8.1, Oracle Database 12c Release 2, WAMP current version.

also edited file php.ini in Apache to have oci_12c.

regards
Reply




Theme © iAndrew 2016 - Forum software by © MyBB