简体   繁体   中英

Can't use database query in codeigniter and oracle

I already set up my connection to oracle 11g, I can see the log-in page, but when I proceed to log-in, no record display or I can't log-in. I tried to put code to check if I'm connected to database when loading the model. If return TRUE then Im connected, but it always return FALSE and show the echo 'No database selected'. What would be the possible cause? Are there any differences on creating queries using mysql and oracle? Do I need to put commit on my code when selecting queries?

Here's my connection. It worked and show the default page.

database.php

$tnsname = '(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.112)(PORT = 1521))
    (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = XE)))';
$db['default']['hostname'] = $tnsname;
$db['default']['username'] = 'test';
$db['default']['password'] = 'testpass';
$db['default']['database'] = 'testdb';
$db['default']['dbdriver'] = 'oci8'; //Oracle 11g
$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;

Here's my code selecting log-in

<?php

class User_db extends CI_model {

    public function get_record($username, $password) {
        if ($this->load->database('default')==FALSE)
        {
           exit('No database connection!');
        }
        $query=$this->db->get_where("tbl_user", array("username"=>$username, "password"=>md5($password)));
        if($query->num_rows()==1) {
            return $query->result();
        }
        else {
            return FALSE;
        }
    }
}
$db['oracle']['hostname'] = '10.10.10.1:1521/ocidb';

have a look

Connecting codeigniter to mysql and oracle in the same application

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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