Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

dimodium's avatar

Trouble to create ORM/DB

Hi.

new to laravel I am doing one of the big tutorials at laracast. Its LAravel from Scratch by Jeffrey Way.

Now in the DB chapter we start using the eloquent DB, first. .And I fail.

Setup is a docker-compose with php / msyl container. Both are up. Both reach each other.

I installed mysql-client on my php container. Both users can - actually - create tables and databases from the PHP container. That shows me, the connection is given and working.

But each artisan command fails. Tried php artisan migrate php artisan migrate:install php artisan migrate:fresh

Always Connection Refused.

application/env: DB_CONNECTION=mysql DB_HOST=lara-kurs-1-mysql DB_PORT=23061 DB_DATABASE=blog DB_USERNAME=root

docker-compose.yml mysql: container_name: lara-kurs-1-mysql image: mysql:5.7 restart: on-failure environment: MYSQL_ROOT_USER: root MYSQL_DATABASE: blog MYSQL_USER: 'root' MYSQL_PASSWORD: 'r00t' ports: - "23061:3306" DB_PASSWORD=r00t

Always the same error:

SQLSTATE[HY000] [2002] Connection refused (Connection: mysql, SQL: select * from information_schema.tables where table_schema = blog and table_name = migrations and table_type = 'BASE TABLE')

at vendor/laravel/framework/src/Illuminate/Database/Connection.php:793 789▕ // If an exception occurs when attempting to run a query, we'll format the error 790▕ // message to include the bindings with SQL, which will make this exception a 791▕ // lot more helpful to the developer instead of just the database's errors. 792▕ catch (Exception $e) { ➜ 793▕ throw new QueryException( 794▕ $this->getName(), $query, $this->prepareBindings($bindings), $e 795▕ ); 796▕ } 797▕ }

Any hint for me?

Regards D

ps:: The problem is the select query.

select * from information_schema.tables where table_schema = blog and table_name = migrations and table_type = 'BASE TABLE')

It should be _schema = "blog" and _name = "migrations". But got this in all laravel versions I have tried.

0 likes
1 reply
jlrdw's avatar

Maybe to just get started, try Xampp if on windows.

I just use the downloaded zip versions of PHP, MySql, and Apache and just setup myself.

Tricky the first time, but once you do it, it's easy the next time. There are tons of tutorials. But I just follow the documentation from the sites I download from. If WIndows, make sure you get the correct php and apache and mysql versions for WIndows.

If using Linux, I suggest using Nginx while learning.

Linux has a bigger learning curve at setting up all of this, but I found some tutorials on Digital Ocean that helped me. I develop on WIndows and Linux.

Take notes when you do anything, so the next time it will be easier.

Edit:

Watch out for some of those Youtube videos.

There are some that do not show the correct and secure way to setup laravel.

Please or to participate in this conversation.