1
votes

I am new on codeigniter 3.0 . I am uploading my project on my server. but i am facing some errors that have stuck me. But it is working fine on local. i have googled but did not find my answers. I think there are some database configuration issue.

Here is my database.php

$db['default'] = array(
'dsn'   => '',
'hostname' => 'http://selectomobile.com/freber',
'username' => 'my username',
'password' => 'mypassword',
'database' => 'mydatabasename',
'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,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => TRUE

);

There are some errors that are irritating me.

1.

A PHP Error was encountered Severity: Warning Message: mysqli::real_connect(): php_network_getaddresses: getaddrinfo failed: Name or service not known Filename: mysqli/mysqli_driver.php Line Number: 161 Backtrace: File: /home/selectom/public_html/freber/index.php Line: 292 Function: require_once

2.

A PHP Error was encountered Severity: Warning Message: mysqli::real_connect(): (HY000/2002): php_network_getaddresses: getaddrinfo failed: Name or service not known Filename: mysqli/mysqli_driver.php Line Number: 161 Backtrace: File: /home/selectom/public_html/freber/index.php Line: 292 Function: require_once

3.

A PHP Error was encountered Severity: Warning Message: Cannot modify header information - headers already sent by (output started at /home/selectom/public_html/freber/system/core/Exceptions.php:272) Filename: core/Common.php Line Number: 568 Backtrace: File: /home/selectom/public_html/freber/index.php Line: 292 Function: require_once

4.

A Database Error Occurred Unable to connect to your database server using the provided settings. Filename: core/CodeIgniter.php Line Number: 500

1
I am simply run [link] (selectomobile.com/freber). - Hamaad Hussain
If you have cPanel on server, see mysql server address there. It is NOT your website/application link. Can be checked in phpmyadmin too, or if you don't have cPanel installed you can set it as localhost or IP address of server where MySQL is installed. - Tpojka

1 Answers

0
votes

Your code is wrong

Your code

$db['default'] = array(
'dsn'   => '',
'hostname' => 'http://selectomobile.com/freber', # Wrong 
'username' => 'my username',
'password' => 'mypassword',
'database' => 'mydatabasename',
'dbdriver' => 'mysqli',
'dbprefix' => '',
'pconnect' => FALSE, # don't change this
'db_debug' => (ENVIRONMENT !== 'production'), # Wrong 
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => TRUE # There is no such config
);

Mine (Database Configuration Codeigniter)

$db['default'] = array(
    'dsn'   => '',
    'hostname' => 'localhost', # this should be localhost
    'username' => 'root', # username which creates from DB wizard
    'password' => '', # password which creates from DB wizard
    'database' => 'database_name',
    'dbdriver' => 'mysqli',
    'dbprefix' => '',
    'pconnect' => TRUE,
    'db_debug' => TRUE, # Changed
    'cache_on' => FALSE,
    'cachedir' => '',
    'char_set' => 'utf8',
    'dbcollat' => 'utf8_general_ci',
    'swap_pre' => '',
    'encrypt' => FALSE,
    'compress' => FALSE,
    'stricton' => FALSE,
    'failover' => array()
);

To change environment

Go to index.php in root. (if CI3 Line 56)

define('ENVIRONMENT', isset($_SERVER['CI_ENV']) ? $_SERVER['CI_ENV'] : 'development');

Available environments

  1. development
  2. testing
  3. production