Jump to content

Recommended Posts

Please help! i can't connect codeigniter to Oracle

I am trying to connect Codeigniter to Oracle 11g, here are my settings

 

 

Settings in database.php:

$active_group = 'default';
   $active_record = TRUE;
   $db['default']['hostname'] = "//localhost/";
   $db['default']['username'] = 'xxxxxxx';
   $db['default']['password'] = 'xxxxxxx';
   $db['default']['database'] = 'orcl';
   $db['default']['dbdriver'] = 'oci8';
   $db['default']['dbprefix'] = '';
   $db['default']['pconnect'] = TRUE;
   $db['default']['db_debug'] = TRUE;
   $db['default']['cache_on'] = FALSE;
   $db['default']['cachedir'] = '';
   $db['default']['char_set'] = 'utf8';
   $db['default']['dbcollat'] = 'utf8_general_ci';
   $db['default']['swap_pre'] = '';
   $db['default']['autoinit'] = TRUE;
   $db['default']['stricton'] = FALSE;

 

 

Note: I added the C:\instantclient_11_2 to environment variable to PATH.

 

Oracle :

oracle port number: 1521

oracle hostname: Home-pc

database name: orcl

 

 

Only when I run my CodeIgniter login code it shows this error message:

 

A Database Error Occurred

 

Unable to connect to your database server using the provided settings.

 

Filename: D:\xampp\htdocs\ci\system\database\DB_driver.php

 

Line Number: 124

 

But I can connect to Oracle when I run a simple php code like:

 

<?php
   $conn = oci_connect("xxxxxx", "xxxxxx","");
   if (!$conn) { 
      echo "Not connected!";
   }
   else
     echo "yahooooooooo!!!!!!!!!!";
   ?>

Result:

yahooooooooo!!!!!!!!!!

Link to comment
https://forums.phpfreaks.com/topic/272319-cant-connect-codeigniter-to-oracle/
Share on other sites

  • 2 weeks later...

CodeIgniter always allows you to use libraries folder to put your own php code so that you can later use them.

 

So create a php file like Oracleconnect.php in your libraries. Put your code there and access the function like this:

 

Suppose, you have created a class in your OracleConnect.php

 

class Oracleconnect {
public function __construct() {

}

public function functionName() {
 $conn = oci_connect("xxxxxx", "xxxxxx","");
 if (!$conn) {
	 echo "Not connected!";
 }
 else
	 echo "yahooooooooo!!!!!!!!!!";
}

 

Now in your controller, call that library file:

 

//a function to load library and passing values to views
 public function getconnect() {
	 $this->load->library('oracleconnect');

	 $data['output']= $this->oracleconnect->functionName();

	 $this->load->view('main', $data);
 }

 

In your view (suppose that is main.php) you will get the output, you wanted.

Edited by Sanjib Sinha
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.