CodeIgniter Forums
Mysqli on WAMP, error - connection attempt failed - Printable Version

+- CodeIgniter Forums (
+-- Forum: Using CodeIgniter (
+--- Forum: General Help (
+--- Thread: Mysqli on WAMP, error - connection attempt failed (/showthread.php?tid=63884)

Mysqli on WAMP, error - connection attempt failed - StudentX - 12-18-2015

Hello Everybody,

I am working on my first Codeigniter project. Recently I migrated this project to Windows 10 from Windows 7, in Windows 7, I was working with manual installation of Apache, PHP, Mysql but in Windows 10 I installed WAMP.

And I am getting following error message in this new setup. The page keeps on loading and loading and then fails with the error message. The mysqli extention is installed and loaded.

Quote:A PHP Error was encountered
Severity: Warning
Message: mysqli::real_connect(): (HY000/2002): A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
Filename: mysqli/mysqli_driver.php
Line Number: 135

Further done the page this is the message I get :
Quote:Unable to connect to your database server using the provided settings.

If I change 'dbdriver' => 'mysqli', part of the config to 'dbdriver' => 'mysql', then it works but shows a warning of deprecated mysql extension.

$db['default'] = array(
   'dsn'   => '',
   'hostname' => 'localhost',
   'username' => 'root',
   'password' => '',
   'database' => 'studentx',
   'dbdriver' => 'mysqli', // This one here.
   'dbprefix' => '',
   'pconnect' => FALSE,
   'db_debug' => TRUE,
   'cache_on' => FALSE,
   'cachedir' => '',
   'char_set' => 'utf8',
   'dbcollat' => 'utf8_general_ci',
   'swap_pre' => '',
   'encrypt' => FALSE,
   'compress' => FALSE,
   'stricton' => FALSE,
   'failover' => array(),
   'save_queries' => TRUE

I checked my phpinfo and the mysqli is installed. I checked it with the following code and it is working.

$mysqli = new mysqli("localhost", "root", "", "myDatabase");

/* check connection */
if ($mysqli->connect_errno) {
   printf("Connect failed: %s\n", $mysqli->connect_error);

/* check if server is alive */
if ($mysqli->ping()) {
   printf ("Our connection is ok!\n");
} else {
   printf ("Error: %s\n", $mysqli->error);

/* close connection */

/*** Results in : Our connection is ok! ***/

1. wamp icon > php > php_extensions > php_mysqli
2. extension=php_mysqli.dll in php ini is un-commented.
3. The extension_dir" c:/wamp/bin/php/php5.5.12/ext/ is correct for my php version install.
4. I tried it with the fresh install of the codeigniter, simply adding $this->load->database ( ) to the default controller triggers the same error.

I created a virtual host for this project do here is info about it.

HOST file :

Code:       localhost
::1             localhost       myProject
::1             myProject

Apache httpd-vhosts.conf file :

<VirtualHost *:80>
   ServerAdmin [email protected]
   DocumentRoot "c:/wamp/www"
   ServerName localhost
   ServerAlias localhost
   <Directory  "c:/wamp/www">
       Options Indexes FollowSymLinks
       AllowOverride All
       Require local

<VirtualHost *:80>
   ServerAdmin [email protected]
   DocumentRoot "c:/wamp/www/myProject/www"
   ServerName myProject
   ServerAlias myProject
   ErrorLog "logs/myProject-error.log"
   CustomLog "logs/myProject-access.log" common
   <Directory  "c:/wamp/www/myProject/www">
       Options Indexes FollowSymLinks
       AllowOverride All
       Require local

Project .htaccess file :

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]  

<Files "index.php">
AcceptPathInfo On

<IfModule !mod_rewrite.c>

ErrorDocument 404 /index.php

So, how do I make mysqli work for codeigniter ?

RE: Mysqli on WAMP, error - connection attempt failed - StudentX - 12-18-2015

No one ?

Could it be a BUG ?

RE: Mysqli on WAMP, error - connection attempt failed - arma7x - 12-19-2015

Have you try as hostname? Not sure if it's works or not..

RE: Mysqli on WAMP, error - connection attempt failed - InsiteFX - 12-19-2015

I had the same problem when I upgraded to Windows 10 on XAMPP If your running any kind of remote software like Skype and Team Viewer you need to change the port number to something other then port 80.

Also try re-installing WAMP and see if it will connect.

After re-installing XAMPP several times it did finally work.