CodeIgniter Forums
Migration: Unable to connect to the database. - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: Migration: Unable to connect to the database. (/showthread.php?tid=78539)



Migration: Unable to connect to the database. - superior - 02-05-2021

Hello,

I've decided to move our application to the newer version of CodeIgniter 4, to do this we will migrate our queries to keep track of changes and rollback if needed. To do this we use the build in migration tool, we did use this in the CodeIgniter 3 as well, but unfortunately we've encountered an issue and i can't seem to find the issue.

The database credentials are 100% correct, i can confirm the connection with HeidiSQL to be successfully. Did i miss something that's required in order to get a connection? I've used the .env file to change these credentials, have read it's more practical for different environments.

What did i use:
I've read through the Github issues it's better to use a IP-based hostname, so i've set this. Can see in my var_dump() the port is already set so that's not required. The driver is available as well, it's an Ubuntu 20.0.4 server i'm building on (server).

Server information:
  • Linux Ubuntu 20.04 LTS
  • PHP 8.0.1 (can downgrade if required)
  • Nginx
  • MariaDB 10.3
Checked:
On command: php -m
I can see MySQLi in the list of installed modules

Are there any more requirements to connect?

Kind Regards


RE: Migration: Unable to connect to the database. - paulbalandan - 02-05-2021

Check your logs file for the specific error message thrown.


RE: Migration: Unable to connect to the database. - superior - 02-05-2021

(02-05-2021, 04:40 AM)paulbalandan Wrote: Check your logs file for the specific error message thrown.

Hi,

Nothing to identify the reason it shouldn't work, it simply states there isn't a connection.

Screen when running: 'php spark migrate'
> https://ibb.co/LNmhkDF

Edit:
When running it through PHP like ' echo command('migrate') ' it works without any issues.
The problem seems to be spark not able to run, have no idea what is going wrong.


RE: Migration: Unable to connect to the database. - InsiteFX - 02-05-2021

Did you move any of the CodeIgniter folders? Spark looks for the public folder in the root
where it is if you move the public folder you need to edit the spark file and tell it where
the public folder is.


RE: Migration: Unable to connect to the database. - superior - 02-05-2021

(02-05-2021, 12:33 PM)InsiteFX Wrote: Did you move any of the CodeIgniter folders? Spark looks for the public folder in the root
where it is if you move the public folder you need to edit the spark file and tell it where
the public folder is.

It's a default installation so no folders where moved or renamed, the only file i've editted was the .env file. Have renamed it with a dot at the beginning and changed the credentials.

Should i've been inside the public folder when running spark or should the main root work as well?


RE: Migration: Unable to connect to the database. - ikesela - 02-05-2021

you need to enable PHP extension for php 8,

intl
mysqli


RE: Migration: Unable to connect to the database. - superior - 02-05-2021

(02-05-2021, 01:56 PM)ikesela Wrote: you need to enable PHP extension for php 8,

intl
mysqli

Hi,

The server runs PHP 8.0.1, on my local machine it's PHP 7.4.6 with both extensions loaded. This is required from the start when you install from a single composer command, but thank you for the suggestion.

Issue still remains also on a local database, same issue with 100% correct credentials.


RE: Migration: Unable to connect to the database. - superior - 02-06-2021

other commands like create a file does work, it's not possible to connect to my database through spark. Via the controller with a simple echo command works without any issues.


RE: Migration: Unable to connect to the database. - paulbalandan - 02-06-2021

Please set your logging threshold to 4 in app/Config/Logger.php if not yet set to 4. Run the migrations again in spark. After the cli shows the error, go to writable/logs/ and look for the log file for the day and check the latest entries. You should be looking for logs with "ERROR -->"


RE: Migration: Unable to connect to the database. - superior - 02-06-2021

(02-06-2021, 09:23 AM)paulbalandan Wrote: Please set your logging threshold to 4 in app/Config/Logger.php if not yet set to 4. Run the migrations again in spark. After the cli shows the error, go to writable/logs/ and look for the log file for the day and check the latest entries. You should be looking for logs with "ERROR -->"

> ERROR - 2021-02-06 10:36:31 --> Error connecting to the database: Class 'SQLite3' not found

My .env looks like this (credentials removed)

Code:
#--------------------------------------------------------------------
# DATABASE
#--------------------------------------------------------------------

database.default.hostname =
database.default.database =
database.default.username =
database.default.password =
database.default.DBDriver = MySQLi


Why is it looking voor SQLLite3, and shouldn't this be installed using the composer command?
Also i'm on 'development' mode, i thought this was only used in testing mode?


EDIT:
-------------------------------
My mistake, shouldn't have used the --all in the command, it triggers something else.

> wrong:  php spark migrate --all
> correct: php spark migrate