Welcome Guest, Not a member yet? Register   Sign In
Fatal error: Call to a member function num_rows() on a non-object
#1

[eluser]huangxiao[/eluser]
Hi, I need help please why is that num_rows() function is error when I am connected to MSSQLSERVER?


$username = $this->input->post('username');
$password = $this->input->post('password');

$query = $this->db->query("SELECT * FROM stdtbl where username='$username' and password='$password'");

if ($query->num_rows() > 0)//it raises error here.
{
$row = $query->row();

return true;
}

Thank you in advance

#2

[eluser]InsiteFX[/eluser]
Did you load the database?

The error means it cannot find the database or it did not return any data.
#3

[eluser]huangxiao[/eluser]
[quote author="InsiteFX" date="1396027177"]Did you load the database?

The error means it cannot find the database or it did not return any data.
[/quote]


Yes this my config.

Code:
$active_group = 'default';
$active_record = TRUE;

$db['default']['hostname'] = 'CARL-PC';
$db['default']['username'] = 'mytest';
$db['default']['password'] = 'mypass123';
$db['default']['database'] = 'mydb';
$db['default']['dbdriver'] = 'sqlsrv';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = FALSE;
$db['default']['db_debug'] = FALSE;
$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;

and in autoload.php

$autoload['libraries'] = array('database','session');

Thank you in advance.
#4

[eluser]Tim Brownlaw[/eluser]
Another thing you can do to "dig" into this, is to use

var_dump($query);
after you have performed the query and pick through the results to see whats happening... Plus you'll see the resulting SQL.

An easier way to see the generated SQL is plonk
echo $this->db->last_query();
after your query...

See if that helps to shed any light on the situation!

Cheers
#5

[eluser]rainzzz[/eluser]
Code:
$active_group = 'default';
$active_record = TRUE;

$db['default']['hostname'] = 'Driver={SQL Server};Server=CARL-PC;Database=mydb; Uid=mytest;Pwd=mypass123';
$db['default']['username'] = 'mytest';
$db['default']['password'] = 'mypass123';
$db['default']['database'] = 'mydb';
$db['default']['dbdriver'] = 'obdc';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = FALSE;
$db['default']['db_debug'] = FALSE;
$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;

Try this, I think you get problem with MS SQL connection




Theme © iAndrew 2016 - Forum software by © MyBB