Welcome Guest, Not a member yet? Register   Sign In
Setup Database and check connection
#1

I have my first attempt(i never used a framework) to use CodeIgniter 4.

What I try to achieve is to setup database in CodeIgniter and check in controller if it works.

For database I use MySQL Community Server 8.0.19: https://dev.mysql.com/downloads/mysql/

This is the controller:

Code:
class Testdb extends BaseController{
    
    public function index(){
    
        $db = \Config\Database::connect();
            
    $sel = $db->query("SELECT 1 AS one");
            
    var_dump( mysqli_fetch_assoc($sel)["one"] ); //mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, object given
            
    return view('testdb'); //empty view
        
    }

}

And this is Database.php:

Code:
public $default = [
    'DSN'      => '',
    'hostname' => 'localhost',
    'username' => 'root',
    'password' => 'myPass',
    'database' => 'mydb',
    'DBDriver' => 'MySQLi',
    'DBPrefix' => '',
    'pConnect' => false,
    'DBDebug'  => (ENVIRONMENT !== 'production'),
    'cacheOn'  => false,
    'cacheDir' => '',
    'charset'  => 'utf8mb4',
    'DBCollat' => 'utf8mb4_unicode_ci',
    'swapPre'  => '',
    'encrypt'  => false,
    'compress' => false,
    'strictOn' => false,
    'failover' => [],
    'port'     => 3306,
];

When I check in browser I get this error: `mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, object given`.
I test the connection for db with MySQL Workbench and everything works fine.

What I do wrong and how to fix it?
Reply


Messages In This Thread
Setup Database and check connection - by raul1ro - 03-20-2020, 07:35 AM



Theme © iAndrew 2016 - Forum software by © MyBB