Codeigniter Deprecated: mysql_real_escape_string():

Sofiya picture Sofiya · Aug 4, 2015 · Viewed 25.7k times · Source

Got below error while using codigniter 3.0

FYI using PHP Version 5.5.12,Apache Version Apache/2.4.9 (Win64) PHP/5.5.12

A PHP Error was encountered

Severity: 8192

Message: mysql_real_escape_string(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead

Filename: models/common_model.php

Line Number: 21

Backtrace:

File: C:\wamp\www\Codeigniter\application\models\common_model.php Line: 21 Function: mysql_real_escape_string

Answer

Hassaan picture Hassaan · Aug 4, 2015

Go to application => config => database.php and change from

$db['default']['dbdriver'] = 'mysql';

to

$db['default']['dbdriver'] = 'mysqli';

Note It is recommended to use query builder class for queries.