• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Unable to connect to the database.

#1
Hii, I have just started learning CI4 (moving from CI3 to CI4).

I just followed the tutorial given in the codeigniter official website link- https://codeigniter.com/user_guide/tutorial/index.html


But after making a connection with the database i was facing the unable to connect the database error
and i have checked the connection it is valid but it is not getting connected in CI4 only

error image in attachment.

Please Help Me to resolve the error my env file is also in attachment.


Attached Files Thumbnail(s)
   

.txt   env.txt (Size: 3.4 KB / Downloads: 5)
Reply

#2
there are a few questions that come to mind. I used to use MySQl but quite honestly find sqlite3 easier and since CI4 has a public dir, then my database is outside whats accessible from the web. Sqlite3 is server-less which means you can play with Ci4 and sqlite3on the desktop.

Now a few things come to mind; where on your PC are you running CI4 apache, xampp or other. You don't say you set up a user and password on the database with appropriate grant permissions so i can't guess that you have done that. Obviously if you didn't do that then you won't get a connection to the database.


I mostly don't bother with the env and just edit /Config/Database.php
Reply

#3
Hii captain-sensible and everyone,
My PC configurations are:-

OS - UBUNTU 20.04
PHP Version 7.4.8

Yes i am using Xampp and i have correctly set up the user privileges,as it is working fine for my codeigniter3 projects.

I have edited in Config/Database.php but still the error is there.
Then today i tried some new approach i did the same process in my windows machine and it worked fine.
Then i thought i might have written something wrong in my Ubuntu machine so i made a GitHub repo of the project.
But again i cloned it in Ubuntu machine it started showing the same error.

Do anyone have any idea that why is it giving error. Please HELP !!!
Reply

#4
Set your logs threshold to 4 so that errors will be logged. Then try running it again. Go to your logs then tell us the error message.
Reply

#5
i had same problem
Reply

#6
Hii i have changed the threshold value to 4 and created a log file of today's . I am adding it below
Code:
Code:
CRITICAL - 2020-08-11 10:53:58 --> Unable to connect to the database.

#0 /opt/lampp/htdocs/ignite4/system/Database/BaseConnection.php(646): CodeIgniter\Database\BaseConnection->initialize()

#1 /opt/lampp/htdocs/ignite4/system/Database/BaseBuilder.php(1860): CodeIgniter\Database\BaseConnection->query()

#2 /opt/lampp/htdocs/ignite4/system/Model.php(462): CodeIgniter\Database\BaseBuilder->get()

#3 /opt/lampp/htdocs/ignite4/app/Models/NewsModel.php(12): CodeIgniter\Model->findAll()

#4 /opt/lampp/htdocs/ignite4/app/Controllers/News.php(13): App\Models\NewsModel->getNews()

#5 /opt/lampp/htdocs/ignite4/system/CodeIgniter.php(918): App\Controllers\News->index()

#6 /opt/lampp/htdocs/ignite4/system/CodeIgniter.php(404): CodeIgniter\CodeIgniter->runController()

#7 /opt/lampp/htdocs/ignite4/system/CodeIgniter.php(312): CodeIgniter\CodeIgniter->handleRequest()

#8 /opt/lampp/htdocs/ignite4/public/index.php(45): CodeIgniter\CodeIgniter->run()

#9 /opt/lampp/htdocs/ignite4/system/Commands/Server/rewrite.php(34): require_once('/opt/lampp/htdo...')

#10 {main}

ERROR - 2020-08-11 10:55:33 --> Error connecting to the database:
Call to undefined function CodeIgniter\Database\MySQLi\mysqli_init()

CRITICAL - 2020-08-11 10:55:33 --> Unable to connect to the database.

#0 /opt/lampp/htdocs/ignite4/system/Database/BaseConnection.php(646): CodeIgniter\Database\BaseConnection->initialize()

#1 /opt/lampp/htdocs/ignite4/system/Database/BaseBuilder.php(1860): CodeIgniter\Database\BaseConnection->query()

#2 /opt/lampp/htdocs/ignite4/system/Model.php(462): CodeIgniter\Database\BaseBuilder->get()

#3 /opt/lampp/htdocs/ignite4/app/Models/NewsModel.php(12): CodeIgniter\Model->findAll()

#4 /opt/lampp/htdocs/ignite4/app/Controllers/News.php(13): App\Models\NewsModel->getNews()

#5 /opt/lampp/htdocs/ignite4/system/CodeIgniter.php(918): App\Controllers\News->index()

#6 /opt/lampp/htdocs/ignite4/system/CodeIgniter.php(404): CodeIgniter\CodeIgniter->runController()

#7 /opt/lampp/htdocs/ignite4/system/CodeIgniter.php(312): CodeIgniter\CodeIgniter->handleRequest()

#8 /opt/lampp/htdocs/ignite4/public/index.php(45): CodeIgniter\CodeIgniter->run()

#9 /opt/lampp/htdocs/ignite4/system/Commands/Server/rewrite.php(34): require_once('/opt/lampp/htdo...')

#10 {main}
Reply

#7
one thing about xampp if i understand it correctly is that a lot of stuff is embedded for use so its not necessarily all the same as your native PC.

I use apache web server on slackware

Anything that might be of interest in the phpinfo() of xampp ?

A quick google came up that this is not a Codeigniter issue which is backed up by as you say the same stuff working Windows. F
First thing that came to mind is permissions but..whats your approach to editing stuff as a normal user? since xampp is in /opt and therefore root system ?

So whats your app/Config/database.php settings ?


these are mine for sqlite :


Code:
public $default = [
        'DSN'      => '',
        'hostname' => 'localhost',
        'username' => '',
        'password' => '',
        'database' => ROOTPATH.'writable/Art',
        'DBDriver' => 'SQLite3',
        'DBPrefix' => '',
        'pConnect' => false,
        'DBDebug'  => (ENVIRONMENT !== 'production'),
        'cacheOn'  => false,
        'cacheDir' => '',
        'charset'  => 'utf8',
        'DBCollat' => 'utf8_general_ci',
        'swapPre'  => '',
        'encrypt'  => false,
        'compress' => false,
        'strictOn' => false,
        'failover' => [],
        'port'     => 3306,
    ];
Reply

#8
As it says Call to undefined function CodeIgniter\Database\MySQLi\mysqli_init() you haven't enabled mysqli.

Find your active php.ini and make sure it's on.
Code:
extension=php_mysqli.dll
Reply

#9
extension=php_mysqli.dll is that not windows though ? and hes saying he has an issue on ubuntu linux ? at 3#
Reply

#10
Check your apache log files

drive\xampp\apache\logs
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.