Codeigniter error: Call to undefined function mysql_pconnect()
You are encountering this specific exception because you have upgraded to CodeIgniter 3.0, but your database configuration is still pointing to a driver that no longer exists in that version. The error message Call to undefined function mysql_pconnect() originates from the file system/database/drivers/mysql/mysql_driver.php, specifically at line 135. In CodeIgniter 3, the framework completely removed support for the legacy MySQL extension (mysql_*) and replaced it with the PDO driver.
The tutorial you are following likely assumes a migration path that requires manual intervention regarding database drivers. When you simply swapped the index.php and system directories from version 2.2.4 to 3.0.6, you effectively dropped a layer of abstraction between your application and the database server. In CodeIgniter 2.x, the framework often defaulted to the old mysql driver if no specific configuration was set, but in version 3.x, the default behavior has shifted to using PDO by default for all new installations unless explicitly configured otherwise.
To resolve this, you must inspect your application's database configuration file. Open application/config/database.php. You will likely see a section defining your active database connection. In older versions of CodeIgniter, if the $active_group variable was set to 'mysql', it would attempt to load the legacy driver, triggering the error when the function is not available in the PHP environment or the framework's internal namespace.
The fix involves changing the active group name from mysql to pdo_mysql. Update your configuration array as follows:
$db['default'] = array(
'dsn' => '',
'hostname' => 'localhost',
'username' => 'your_username',
'password' => 'your_password',
'database' => 'your_database',
'dbdriver' => 'pdo_mysql', // Changed from 'mysql' or left blank
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => TRUE,
'charset' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'strickon' => FALSE,
'failover' => array(),
'save_queries' => TRUE
);
By explicitly setting dbdriver to pdo_mysql, you instruct the CodeIgniter 3 core to instantiate the PDO MySQL driver instead of looking for the deprecated mysql_pconnect function. This aligns with modern PHP best practices, as the extension used by the legacy driver was officially removed from PHP 7.0 and later versions. If your server is running a newer version of PHP (which is highly recommended), the old MySQL extension might not be installed at all, causing a fatal error even before CodeIgniter can initialize.
There is also a potential pitfall regarding the pconnect parameter. The legacy mysql_pconnect() function established a persistent connection to the database server. While this can improve performance by reusing connections in long-running scripts, it was deprecated and removed in favor of PDO's connection pooling capabilities or standard connections. In the configuration above, ensure pconnect is set to FALSE. Leaving it as TRUE might cause issues if you are not using a driver that supports persistent connections via PDO, though modern setups typically default to non-persistent connections for stability.
If you have custom controllers like your Main controller extending CI_Controller, the error usually does not stem from the controller logic itself but rather from the initialization of the database library within that constructor or any subsequent calls made during the request lifecycle. The stack trace points to line 10 in Main.php calling parent::__construct(). This parent call triggers the loading of the database driver defined in the configuration file, which is where the lookup for mysql_pconnect fails.
Once you update the database.php file and clear your output cache if you are using any caching mechanisms, the application should initialize correctly without throwing an exception. If you continue to face issues, verify that your PHP installation supports PDO MySQL by running php -m | grep pdo_mysql.
