Welcome Guest, Not a member yet? Register   Sign In
'Severity: Warning --> ocirowcount() expects parameter 1 to be resource, null given' and other errors...HELP!
#1

[eluser]phpworker[/eluser]
I am working on login() method of my app. My platform is Windows, Apache, Oracle db, php5.

This is controllers/main.php file fragment:

Code:
function login()
    {
        parent::Controller();
        $this->load->library('Validation');
            $data['login'] = $this->input->post('login');
            $data['password'] = $this->input->post('password');

            $rules['login']     = "required|max_length[100]|xss_clean";
            $rules['password']     = "required|max_length[100]|xss_clean";

            $this->validation->set_rules($rules);

            if ($this->validation->run() == FALSE)    // walidacja danych
            {
                $this->content->message($this->validation->error_string);
                $this->content->generate('login', $data);
              }else        // weryfikacja loginu i hasÅ‚a
            {
                
            $login_query = $this->db->query('SELECT id,login,password,name,group_id FROM '.$this->tb['users'].' where login='.$data['login'].' and password='.$data['password']);


                if($login_query == false)
                {
                    $this->logmsg->debug('login(): query() returned false');
                }else
                {

foreach ($login_query->result_array() as $r)
                    {
                    $d1 = array(
[line 136 here:]              'user_id'         => $r['id']
                               ,'login'          => $r['login']
                               ,'user_name'       => $r['name'].' '.$r['surname']
                               ,'group_id'         => $r['group_id']
                    );
                    }
                    $this->logmsg->debug('login(): cookies to be set: '.print_r($d1, true));

                    $this->session->set_userdata($d1);
                    $login_query->free_result();

                    redirect('main','location');

                }
            }
    }

I get these errors in my log file:

Code:
(...)
DEBUG - 2007-08-14 10:45:26 --> Model Class Initialized
ERROR - 2007-08-14 10:45:26 --> Severity: Warning  --> ocirowcount() expects parameter 1 to be resource, null given /usr/local/apache2/htdocs/krzysztofk/aq/05a/system/database/drivers/oci8/oci8_driver.php 358
(...)
ERROR - 2007-08-14 10:45:26 --> Severity: Notice  --> Undefined index:  id /usr/local/apache2/htdocs/krzysztofk/aq/05a/system/application/controllers/main.php 136
ERROR - 2007-08-14 10:45:26 --> Severity: Notice  --> Undefined index:  login /usr/local/apache2/htdocs/krzysztofk/aq/05a/system/application/controllers/main.php 137
ERROR - 2007-08-14 10:45:26 --> Severity: Notice  --> Undefined index:  name /usr/local/apache2/htdocs/krzysztofk/aq/05a/system/application/controllers/main.php 138
ERROR - 2007-08-14 10:45:26 --> Severity: Notice  --> Undefined index:  surname /usr/local/apache2/htdocs/krzysztofk/aq/05a/system/application/controllers/main.php 138
ERROR - 2007-08-14 10:45:26 --> Severity: Notice  --> Undefined index:  group_id /usr/local/apache2/htdocs/krzysztofk/aq/05a/system/application/controllers/main.php 139
DEBUG - 2007-08-14 10:45:26 --> login(): cookies to be set: Array
(
    [user_id] =>
    [login] =>
    [user_name] =>  
    [group_id] =>
)

ERROR - 2007-08-14 10:45:26 --> Severity: Warning  --> Cannot modify header information - headers already sent by (output started at /usr/local/apache2/htdocs/krzysztofk/aq/05a/system/libraries/Exceptions.php:164) /usr/local/apache2/htdocs/krzysztofk/aq/05a/system/libraries/Session.php 282
ERROR - 2007-08-14 10:45:26 --> Severity: Warning  --> Cannot modify header information - headers already sent by (output started at /usr/local/apache2/htdocs/krzysztofk/aq/05a/system/libraries/Exceptions.php:164) /usr/local/apache2/htdocs/krzysztofk/aq/05a/system/helpers/url_helper.php 447

On the screen I enter login, password, press login button and then I got this:

Code:
A PHP Error was encountered

Severity: Notice

Message: Undefined index: id

Filename: controllers/main.php

Line Number: 136
A PHP Error was encountered

Severity: Notice

Message: Undefined index: login

Filename: controllers/main.php

Line Number: 137
A PHP Error was encountered

Severity: Notice

Message: Undefined index: name

Filename: controllers/main.php

Line Number: 138
A PHP Error was encountered

Severity: Notice

Message: Undefined index: surname

Filename: controllers/main.php

Line Number: 138
A PHP Error was encountered

Severity: Notice

Message: Undefined index: group_id

Filename: controllers/main.php

Line Number: 139
A PHP Error was encountered

Severity: Warning

Message: Cannot modify header information - headers already sent by (output started at /usr/local/apache2/htdocs/krzysztofk/aq/05a/system/libraries/Exceptions.php:164)

Filename: libraries/Session.php

Line Number: 282
A PHP Error was encountered

Severity: Warning

Message: Cannot modify header information - headers already sent by (output started at /usr/local/apache2/htdocs/krzysztofk/aq/05a/system/libraries/Exceptions.php:164)

Filename: helpers/url_helper.php

Line Number: 447

I like CodeIgniter a lot, so I gave myself a chance of using it.
I think learning by using is the best method so I started next project with CI and now I am late! A few days fighting took no results... I only realized there's something wrong with oci8 database library.

Please, HELP!!

PS. Later, I will describe in details (tutorials) my project on my blog so, some new, talented Polish programmers would take CI idea and spread it to the world Wink
#2

[eluser]kgill[/eluser]
All your errors are because of the very first one:

ocirowcount() expects parameter 1 to be resource, null given

The only parameter ocirowcount has is a statement id, if that's null it means your SQL didn't parse properly.

Just glancing at your SQL statement, you're dumping the login and password variables directly into the query and not quoting them, I'm pretty certain those are going to be varchar2 columns. So take this:
Code:
$login_query = $this->db->query('SELECT id,login,password,name,group_id FROM '.$this->tb['users'].' where login='.$data['login'].' and password='.$data['password']);
and rewrite it to properly quote the strings:
Code:
$sql = "SELECT id,login,password,name,group_id FROM ".$this->tb['users']." where login='".$data['login']."' and password='".$data['password']."'";
$login_query = $this->db->query($sql);

Fix that and the Undefined index errors should go away, those are because your $login_query->result_array() is empty (since the query didn't execute) so the index id, login, etc. don't exist.

- K
#3

[eluser]phpworker[/eluser]
Thanks for answer!

I've just used the solution you have posted and there's no change in results...

Also, I converted column names and index names to uppercase - no success here.

Than I tested the query through Oracle SQL Developer - no problem, everything works fine.

I think of creating new CI library or modyfying the one, because it seems to be faster solution than fighting the code.

Maybe then I will better understand what I did wrong...

Thanks for help!
#4

[eluser]kgill[/eluser]
How did you test the query? echo $sql out and copy/paste that into developer? I can verify that the CI oracle libraries do work, one of my production boxes has 1.5.3 running with PHP5 and connecting to a 10g database.

- K
#5

[eluser]Michael Wales[/eluser]
Just curious here - I gave a quick review of your code and I can't spot out exactly what is going wrong - but maybe changing your code a bit, to only expect one row (since that's all you need to test for in a validation scenario) can correct the issue.

Code:
// Add a limit
$login_query = $this->db->query('SELECT id,login,password,name,group_id FROM '.$this->tb['users'].' where login='.$data['login'].' and password='.$data['password'] . ' LIMIT 1,0');

// Test for a literal false, not just 0 or an unset variable
if( ($login_query === FALSE) || ($login_query->num_rows() != 1)) {
  $this->logmsg->debug('login(): query() returned false');
} else {
  // We only need one row - why loop it?
  $r = $login_query->row();
  $d1 = array('user_id' => $r->id,
              'login' => $r->login,
              'user_name' => $r->name . ' ' . $r->surname,
              'group_id' => $r->group_id);
}

As I side, fundamentally this is the same, but maybe it will correct your issue in a round-about way. Regardless, you're getting rid of a loop that you don't need so execution time and resources should drop a bit.
#6

[eluser]Michael Wales[/eluser]
Now that I am looking over your code - this line is what I think may possibly be the issue:
Code:
foreach ($login_query->result_array() as $r)

I'm just thinking out loud here - I have no idea but tossing ideas out to help you correct the issue. Try assigning $login_query->result_array() to a variable, then print_r it. I'm thinking what may be happening is there is another level within the array that isn't being accounted for - so your loop would actually look something like this:
Code:
$d1 = array('user_id'=>$r[0]['id']);

Worth a shot - to see what exactly the result_array() function is returning.
#7

[eluser]phpworker[/eluser]
walesmd: thanks for your suggestions. I tried a few methods of getting db data into the array, not using foreach() is one of them. No success here... As I posted in my first post of this thread, return array looks like this (result generated with print_r()):

Code:
Array
(
    [user_id] =>
    [login] =>
    [user_name] =>  
    [group_id] =>
)

I did not try this:

Code:
$d1 = array('user_id'=>$r[0]['id']);

because the array has only a few keys and no one is '[0]'.
Also, the sql result query looks fine and works under sql developer.

I realized that problem is somewhere in oci8 class, so I've created my own one, very easy.

Now trying to make it all workin... :zip:

Thanks for answers!
#8

[eluser]phpworker[/eluser]
[quote author="kgill" date="1187289404"]How did you test the query? echo $sql out and copy/paste that into developer? I can verify that the CI oracle libraries do work, one of my production boxes has 1.5.3 running with PHP5 and connecting to a 10g database.

- K[/quote]

Hi kgill,
I've tested it in a simmilar way to one you described (logs).

We have here CI 1.5.3, php 5.2.0 and Oracle 9.2.

I do not know what I did wrong.

Can you send me your oci8 libs for CI?




Theme © iAndrew 2016 - Forum software by © MyBB