Welcome Guest, Not a member yet? Register   Sign In
Unable to connecte to the database
#1

Hello everyone,

My website won't show on live server because it can't connect to the database. Here is the database configuration:

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

$db['default'] = array(
'dsn' => '',
'hostname' => 'localhost',
'username' => 'user_root',
'password' => '*****',
'database' => 'mydb',
'dbdriver' => 'mysqli',
'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
);


The error messages? Here they are:
1. A PHP Error was encountered

Severity: Warning

Message: mysqli::real_connect(): (HY000/2002): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

Filename: mysqli/mysqli_driver.php

Line Number: 135

Backtrace:

File: /usr/local/pem/vhosts/109098/webspace/httpdocs/mydomain.com/sthes/application/controllers/Home.php
Line: 20
Function: __construct

File: /usr/local/pem/vhosts/109098/webspace/httpdocs/mydomain.com/index.php
Line: 294
Function: require_once

2. A PHP Error was encountered

Severity: Warning

Message: Cannot modify header information - headers already sent by (output started at /usr/local/pem/vhosts/109098/webspace/httpdocs/mydomain.com/sthes/system/core/Exceptions.php:272)

Filename: core/Common.php

Line Number: 564

Backtrace:

File: /usr/local/pem/vhosts/109098/webspace/httpdocs/mydomain.com/sthes/application/controllers/Home.php
Line: 20
Function: __construct

File: /usr/local/pem/vhosts/109098/webspace/httpdocs/mydomain.com/index.php
Line: 294
Function: require_once

3. A Database Error Occurred

Unable to connect to your database server using the provided settings.

Filename: controllers/Home.php

Line Number: 20
Reply
#2

checklist to follow

1) connection details are correct
2) mysql server is running fine
3) check with command line or desktop client with same credential whether connecting fine.

If all above correct, you are done.. you will face no issue.

  Dodgy -Abhijeet
Reply
#3

MySQLi Test Script:

PHP Code:
<?php

DEFINE 
('DB_HOST''database_host');       // The database host ie: loacalhost etc;
DEFINE ('DB_USER''user_name');           // The database users name- root
DEFINE ('DB_PASSWORD''user_password');   // The database password - xxxxxx
DEFINE ('DB_NAME''database_name');       // The database name - my_database

// Connect to the MySQLi Database
$conn mysqli_connect(DB_HOSTDB_USERDB_PASSWORDDB_NAME);

// Check for a MySQLi Connection
if (mysqli_connect_errno())
{
 
   echo "Failed to Connect to MySQL: " mysqli_connect_error();
}
else
{
 
  echo "Connection to MySQLi Ok! " mysqli_connect_error();
}

mysqli_close($conn);

?>
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#4

I wonder why the client tries to connect to the MySQL server through a socket. Is this intended?
Reply
#5

(This post was last modified: 06-09-2016, 08:02 AM by rooye.)

(06-09-2016, 05:28 AM)ivantcholakov Wrote: I wonder why the client tries to connect to the MySQL server through a socket. Is this intended?

I don't know exactly how the issue of connecting through the socket came about. Using CI framework I simply put the data in the config/database.php file.How can I connect to the db without the socket? Thanks ivantcholakov
Reply
#6

(06-09-2016, 03:16 AM)InsiteFX Wrote: MySQLi Test Script:

PHP Code:
<?php

DEFINE 
('DB_HOST''database_host');       // The database host ie: loacalhost etc;
DEFINE ('DB_USER''user_name');           // The database users name- root
DEFINE ('DB_PASSWORD''user_password');   // The database password - xxxxxx
DEFINE ('DB_NAME''database_name');       // The database name - my_database

// Connect to the MySQLi Database
$conn mysqli_connect(DB_HOSTDB_USERDB_PASSWORDDB_NAME);

// Check for a MySQLi Connection
if (mysqli_connect_errno())
{
 
   echo "Failed to Connect to MySQL: " mysqli_connect_error();
}
else
{
 
  echo "Connection to MySQLi Ok! " mysqli_connect_error();
}

mysqli_close($conn);

?>


Thanks you InsiteFX for your suggestion
I simply verified repeatedly that the data I used was correct. Am going to test this code you've given
Reply
#7

I don't see anything wrong in your settings. Use the suggested test by InsiteFX to see whether you can connect to the MySQL server at all, without using CodeIgniter.
Reply
#8

I have tried the code, replacing the content of config/database.php file. As expected it didn't work since CI framework expects an array from this file then it will do the connection itself.
Reply
#9

No just run the code from straight php
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#10

(06-09-2016, 10:42 AM)InsiteFX Wrote: No just run the code from straight php

Hello everyone

Thanks so much for the prompt guide you are giving me. I have used the suggested code of InsiteFx in my index.php (in a manner that eliminates CI) and still could not connect to the DB. The error msg is:

"Failed to Connect to MySQL: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)"

Thanks in advance for further suggestion.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB