Codeigniter error when trying to connect to database using mysqli

后端 未结 10 861
陌清茗
陌清茗 2020-12-21 09:39

I am getting Following error in my CodeIgniter application which is live on server.

Here is the output of the error:

A PHP Error was encounte

相关标签:
10条回答
  • 2020-12-21 10:10

    I had the same trouble. Since I use xampp and I was running my codeigniter app locally, the problem at the end I solved it by remplacing: 'hostname' => 'localhost ' by 'hostname' => '127.0.0.1:33065' the :33065 is the port assigned by default by xampp for phpmyadmin. If you are running your proyect in the xampp default options, changing this, should be enough (hopefully). But if you don´t, I guess, you can search which port you are using for the database conection, and add it to your hostname with ":" (if you are not sure which port you are using, you always can see in your D.B. administration tool -phpmyadmin or the one you are using- on the options, which port is taking).

    0 讨论(0)
  • 2020-12-21 10:11

    The same error I was getting when I upload my codeigniter project from localhost to Live server.

    What solution I find is to make some changes into the application => config => database.php

    Following is the database setting for the

    localhost

    $db['default'] = array(
        'dsn'   => '',
        'hostname' => 'localhost',
        'username' => 'root',
        'password' => '',
        'database' => 'creator',
        '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
    );
    

    Following database setting for

    live server (Just demo, setting differ as per hosting provider)

    1) First you have to create database.

    2) find MySql Databases(or anything related database) on dashboard,

    3) create new database and put database name, username, password.

    4) export database from localhost

    5) open phpmyadmin on live server and import it.

    6) change the setting of application=>config=>database.php by using FTP client or dashboard.

    $db['default'] = array(
        'dsn'   => '',
        'hostname' => 'mysql.hostingprovider.com',    
        'username' => 'abc.username',
        'password' => 'abc.password',
        'database' => 'abc.databasename',
        '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
    );
    
    0 讨论(0)
  • 2020-12-21 10:13

    Connect localhost with port solves the problem for me.

    $db['default'] = array(
        'dsn' => '',
        'hostname' => 'localhost:3308', //Added port here
        'username' => 'root',
        'password' => '1234',
        'database' => 'my_database',
        '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
    );
    
    0 讨论(0)
  • 2020-12-21 10:15

    you have to set mysql port number which is by default 3306 check this in database.php

    use either

    'dbport' => '3306',
    

    or

     'hostname' => 'mysql.hostingprovider.com:3306',   
    
    0 讨论(0)
提交回复
热议问题