• 1 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Call to a member function real_escape_string() on a non-object

#11
(09-02-2015, 01:57 PM)Narf Wrote:
(09-02-2015, 10:47 AM)Mdev Wrote: I have the same problem although i have the autoinit set.
I needed to do this inside the

Quote:C:\work\Codefi UI\codeigniter\system\database\drivers\mysqli\mysqli_driver.php
to make the error go away.


Code:
// --------------------------------------------------------------------

/**
* Platform-dependant string escape
*
* @param    string
* @return    string
*/
protected function _escape_str($str)
{
    if($this->conn_id)
    {
        return $this->conn_id->real_escape_string($str);
    }
}

DO NOT DO THIS! You're making yourself vulnerable to SQL injections!

What do you suggest? I got the same problem
Reply

#12
I'm having the same problem and the "autoinit = TRUE" didn't solve it.

I'm facing this error in my model function:

An uncaught Exception was encountered

Type: Error
Message: Call to a member function real_escape_string() on boolean
Filename: /var/www/html/project/system/database/drivers/mysqli/mysqli_driver.php
Line Number: 391

Backtrace:
File: /var/www/html/project/application/models/FeedCompanies.php
Line: 125
Function: where

This is the function:

public function getCompanyMessages($idCompany)
{
$usersModel = $this->modelslibrary->getModelUsers();
$companiesModel = $this->modelslibrary->getModelCompanies();

$where = array(
$usersModel->table_name.'.id_company' => $idCompany,
$this->table_name.'.deleted' => 'N'
);

$this->db->select(
$this->table_name.'.'.$this->primary_key.', '.
$this->table_name.'.token, '.
$usersModel->table_name.'.id_company, '.
$usersModel->table_name.'.slug, '.
$this->table_name.'.id_user, '.
$this->table_name.'.message, '.
$this->table_name.'.posted_as_company, '.
$this->table_name.'.likes, '.
$this->table_name.'.created_at,
getUserName('.$usersModel->table_name.'.name, '.$usersModel->table_name.'.last_name) as name,
getProfilePhotoURL('.$usersModel->table_name.'.profile_photo) as profile_photo,
getCompanyLogo('.$companiesModel->table_name.'.logo) as company_logo, '.
$companiesModel->table_name.'.name as company_name'
);

$this->db->join($usersModel->table_name, $usersModel->table_name.'.'.$usersModel->primary_key.' = '.$this->table_name.'.id_user');
$this->db->join($companiesModel->table_name, $companiesModel->table_name.'.'.$companiesModel->primary_key.' = '.$usersModel- >table_name.'.id_company');
$this->db->where($where);
$this->db->order_by($this->table_name.'.created_at ASC');

$queryResult = $this->db->get($this->table_name);

if (!$queryResult) return null;

$messages = $queryResult->result_array();

if (!$messages) return null;

return $messages;
}

The line 125 is $this->db->where($where);, so I wrote an echo(var_export($where, true)); before this to get the content of $where array, and the content is just this:

array (
'users.id_company' => 2,
'feed_companies.deleted' => 'N',
)

Why am I having this error and how to solve it?

My environment is:

- CodeIgniter 3.0.4
- PHP 7.2.5
- Ubuntu 16.04
- MySQL Server 5.7.22
- Apache 2.4.18

And here is my config/database.php:

$active_group = 'default';
$query_builder = TRUE;

$db['default'] = array(
'dsn' => '',
'hostname' => '127.0.0.1',
'username' => '{{user}}',
'password' => '{{password}}',
'database' => '{{database}}',
'dbdriver' => 'mysqli',
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => (ENVIRONMENT !== 'production'),
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'autoinit' => TRUE,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => TRUE
);
Reply

#13
Hi to all!

I'm getting randomly the same error since we upgrade CI to 3.1.9

We tried with autoinit = true, but it doesn't solve the issue.

Any idea how to solve it?
English only, no SEO spam
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2018 MyBB Group.