Welcome Guest, Not a member yet? Register   Sign In
Migration: Unable to connect to the database.
#1

(This post was last modified: 02-05-2021, 01:45 AM by superior. Edit Reason: Extra information about the server )

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
Reply
#2

Check your logs file for the specific error message thrown.
Reply
#3

(This post was last modified: 02-05-2021, 08:58 AM by superior.)

(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.
Reply
#4

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.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#5

(This post was last modified: 02-05-2021, 12:47 PM by superior.)

(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?
Reply
#6

you need to enable PHP extension for php 8,

intl
mysqli
Reply
#7

(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.
Reply
#8

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.
Reply
#9

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 -->"
Reply
#10

(This post was last modified: 02-06-2021, 11:52 AM by superior.)

(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
Reply




Theme © iAndrew 2016 - Forum software by © MyBB