CodeIgniter Forums

Full Version: mysqli_sql_exception No such file or directory
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I just started learning codeigniter 4 and faced this problem. I searched a lot and tried some solutions but it is of no use
I am using Ubuntu
[problem : ]
mysqli_sql_exception No such file or directory
There can be a couple of things. A miss/match against your PHP and MySQL version. Or you simply don't have mysqli installed.
(04-14-2020, 09:13 AM)jreklund Wrote: [ -> ]There can be a couple of things. A miss/match against your PHP and MySQL version. Or you simply don't have mysqli installed.


php ver 7.2

mysql ver  10.1.30-MariaDB (with xampp) 

and i have mysqli
How do you connect to your database? Those should be compatible.
(04-14-2020, 11:02 AM)jreklund Wrote: [ -> ]How do you connect to your database? Those should be compatible.

By .env

And on other prject by app/config/database.php
Can you show the code? Just remove the password of course.
Does it instantly die or when you do anything specific?
(04-14-2020, 11:37 AM)jreklund Wrote: [ -> ]Can you show the code? Just remove the password of course.
Does it instantly die or when you do anything specific?

it's simple code

controler
PHP Code:
<?php namespace App\Controllers;
use 
CodeIgniter\Controller;
use 
App\Models\NewsModel;


class 
News extends Controller{
    public function index()
    {
        $model = new NewsModel();
        $data['news'] = $model->findAll();
        echo view('template/all',$data);
    }
    public function show($slug null)
    {
        $model = new NewsModel();
        $db = \Config\Database::connect();
        // $data['news'] = $model->where(['slug'=> $slug])->first();
        $query $db->query('SELECT * FROM news');
        $results $query->getResult();

        $data['news'] = $results;

        echo view('template/show',$data);
    }



model

PHP Code:
<?php

namespace App\Models;

use 
CodeIgniter\Model;

class 
NewsModel extends Model
{
    protected $table 'news';


view

PHP Code:
<!DOCTYPE html>
<
html lang="en">

<
head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>All News</title>
</
head>

<
body>
    <?php
    
if (!empty($news)) {
        foreach ($news as $news_item) {
    ?>
            <div>
                <h4> <?php echo $news_item['title'?> </h4>
                <p> <?php echo $news_item['body'?> </p>
            </div>
        <?php
        
}
    } else {
        ?>
        <h3>No News</h3>

        <p>Unable to find any news for you.</p>
    <?php
    
}
    ?>
</body>

</html> 
help me please
i found the Solution
codeigniter 4 don't working with xampp apache and mysql
but when i installed apache2 and mysql without xampp
everythings are worked successfully
(04-15-2020, 03:07 AM)GamalAbomera Wrote: [ -> ]i found the Solution
codeigniter 4 don't working with xampp apache and mysql
but when i installed apache2 and mysql without xampp
everythings are worked successfully

I was also facing same issue and try different trick to fix but not working. You can believe there is very easy solution to solve this which i've applied. You just need to change host 'localhost' to '127.0.0.1' and go ahead.