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

Muhammad.shahid.shah's avatar

SQLSTATE[HY000] [2002] No connection could be made because the target machine actively refused it. (SQL: select * from `threads` order by `created_at` desc)

1)i am watching the create a forum series and in lesson 2 i am stuck in testing, there if you watch jeff uses sqlite for testing purpose i did same but i am getting above error.i tried changing 127.0.0.1 to localhost and clearing cache, config etc but not working here is my .evn

APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:h90atKo/VaDe9Cgh0dXHrB5kpkq4uGqXcVflJJ6jfAw=
APP_DEBUG=true
APP_LOG_LEVEL=debug
APP_URL=http://localhost

DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=forum
DB_USERNAME=root
DB_PASSWORD=

BROADCAST_DRIVER=log
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null

PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=

my phpunit.xml

<env name="APP_ENV" value="testing"/>
<env name="DB_CONNECTION" value="sqlite"/>
<env name="DB_DATABASE" value=":memory:"/>
env name="CACHE_DRIVER" value="array"/>
<env name="SESSION_DRIVER" value="array"/>
<env name="QUEUE_DRIVER" value="sync"/>
  1. i cannot write test function name util i dont prefix it with test, if i dont do that phpunit gives warning of no test found in test/feature/testclass, while jeff can write without doing it to clear my point -> a_user_can_view_all_threads and when i write i have to write it like this->test_a_user_can_view_all_threads
0 likes
8 replies
tykus's avatar

Regarding the test example, you can use annotations with PHPUnit, i.e. the @test comment

/** @test */
function it_does_the_thing()
{
    // test
}
1 like
Muhammad.shahid.shah's avatar

and i came to know that i cannot access phpmyadmin even, i started server with php artisan serve and now when i try to access 127.0.0.1/phpmyadmin , browser shows this "This site can’t be reached

127.0.0.1 refused to connect Checking the connection Checking the proxy and the firewall "

but when i start xampp then it works what is the problem that server started by php artisan serve cannot access mysql i,e phpmyadmin?

tykus's avatar

XAMPP has PHP, web server, and database server bundled together - php artisan serve does not. You probably do not have a MySQL database running whenever XAMPP is not running.

Muhammad.shahid.shah's avatar

but in past i was able to use php artisan serve with out running xampp, this problem occured today i think i dont know why, i can carry on using xampp but i want to do it with php artisan serve now i have to understand the reason and the solution.so i have stopped my process(creating a forum series) and searching for the problem.

Muhammad.shahid.shah's avatar
Level 2

ok correct me if i am wrong, i think i misleaded my self. so may be in past i didnt knew and may be xampp running in background and i didnt noticed it. ok what u people say we can interact with database using php artisan serve without using (xampp/laragon etc)?in my case i cannot, and i think its problem that can be solved or i am just wasting my time i mean newbies will do stuff like that i wasted(may be it give some fruit) my whole day on this?

the answer is no its not possible to access phpmyadmin or interact with database by using only php artisan serve and not using laragon,xampp etc?

2 likes
YoungM's avatar

I had the same problem once but in my own case I was running on local server. I later discovered that the error:

"PDOException with message 'SQLSTATE[HY000] [2002] No connection could be made because the target machine actively refused it."

was because i have not started Apache and MySQL in Xampp control panel, so the application could not fetch the desired result because there was no coonection.

Immediately I started both Apache and MySQL in Xampp control panel, the error was fixed.

Hope this works for you

1 like
alirez's avatar

hey i think the point is to run mysql as a service, and there is nothing to do with xampp, because it's just a installer of services for development and nothing more. to start mysql as a service you can just run

net start  mysql

in command prompt.

Please or to participate in this conversation.