GETTING SQLSTATE

      12
An error suddenly occurred while I was debugging my code. It has this series of errors regarding the connection to lớn database.

Bạn đang xem: Getting sqlstate

ERROR: SQLSTATE <2002> No connection could be made because the target machine actively refused it.( ! ) Fatal error: Uncaught exception "PDOException" with message " in C:wampwwwwebmainusers.php on line 15( ! ) PDOException: SQLSTATE <2002> No connection could be made because the target machine actively refused it. In C:wampwwwwebmainusers.php on line 15this is the code of where the error is pointing

function __construct() $this->con = new PDO("mysql:host=".$this->host.";dbname=".$this->db,$this->user,$this->pass); I don"t know what to bởi since I bởi vì not usually get problems like this so I haven"t studied much about WAMP. Thank You for your help.


nói qua
Follow
edited Jul 8, 2019 at 14:32
*

Eric McWinNEr
49566 silver badges1818 bronze badges
asked Mar 20, 2014 at 4:07
*

user3406220user3406220
35711 gold badge44 silver badges1010 bronze badges
7
| Show 2 more comments

16 Answers 16


Sorted by: Reset to default
Highest score (default) Trending (recent votes count more) Date modified (newest first) Date created (oldest first)
49
If the WAMP icon is Orange then one of the services has not started.

In your case it looks like MySQL has not started as you are getting the message that indicates there is no server running & therefore listening for requests.

Look at the mysql log and if that tells you nothing look at the Windows event log, in the Windows -> Applications section. Error messages in there are pretty good at identifying the cause of MySQL failing to lớn start.

Sometimes this is caused by a my.ini tệp tin from another install being picked up by WAMPServers MySQL, normally in the windows or windowssystem32 folders. Vì a search for "my.ini" and "my.cnf" and if you find one of these anywhere outside of the wamp.... Folder structure then delete it, or at least rename it so it wont be found. Then restart the MySQL service.


mô tả
Follow
edited Dec 4, 2016 at 14:46
answered Mar 20, năm trước at 9:10
*

RiggsFollyRiggsFolly
91.7k2020 gold badges102102 silver badges146146 bronze badges
0
địa chỉ a phản hồi |
11
I had a similar issue when trying lớn migrate a Drupal website from one local host to another. From Mac running XAMMP to lớn Windows running WAMP.

This was the error message I kept getting when trying lớn access the pages of the website.

PDOException: SQLSTATE <2002> No connection could be made because the target machine actively refused it. In drupal_get_installed_schema_version() (line 155 of C:wampwwwchiaincludesinstall.inc).In settings.php, I"ve changed everything correctly, database name, user and password.

$databases = array ( "default" => array ( "default" => array ( "database" => "mydatabasename", "username" => "mydbusername", "password" => "mydbpass", "host" => "localhost", "port" => "8889", "driver" => "mysql", "prefix" => "", ), ),);After a couple of hours of mindless google searching I"ve changed the port khổng lồ a empty value:

"port" => "",And after that the site loaded properly.


giới thiệu
Follow
answered May 28, 2015 at 17:41
*

igorMigorM
14611 gold badge22 silver badges66 bronze badges
2
showroom a comment |
11
Possibly using different Port for MySQL than using in your Code

*

$conn = new PDO("mysql:host=".SERVER_NAME.";port=3307;dbname=".DB_NAME, DB_USER, DB_PASS);Both ports should be same.

Xem thêm: Hướng Dẫn Cách Mở File Iso Trên Win 10, Mở File Iso Trên Win 10


share
Follow
edited Jan 3, 2018 at 0:27
*

mickmackusa
40.2k1111 gold badges8080 silver badges121121 bronze badges
answered Jan 2, 2018 at 23:22
ntthusharantthushara
30133 silver badges55 bronze badges
địa chỉ a comment |
2
Check whether MySQL vps is running at all. If you not run apache server(or any hệ thống you use) this could happen. After run your local server and refresh the page.


nội dung
Follow
answered Jan 21, 2021 at 10:31
qazisajjadakbarqazisajjadakbar
27522 silver badges33 bronze badges
add a phản hồi |
1
Restart your wampServer... That should solve it.and if it doesn"t..Resta


tóm tắt
Follow
answered Jan 20, 2017 at 12:15
David SaintDavid Saint
2955 bronze badges
địa chỉ cửa hàng a phản hồi |
1
Ensure your WAMP vps (or XAMP) is working, i.e. The wamp icon should be green.


nội dung
Follow
answered Nov 12, 2020 at 6:43
Michael KiarieMichael Kiarie
1,23788 silver badges88 bronze badges
địa chỉ a bình luận |
0
Delete the following files from the directory:

wampinmysqlmysql5.6.17ib_logfile0wampinmysqlmysql5.6.17ib_logfile1wampinmysqlmysql5.6.17ibdata1This solved my problem.


chia sẻ
Follow
edited Mar 18, 2017 at 12:43
answered Jun 9, 2016 at 10:48
Nithiyakumar KNithiyakumar K
2433 silver badges1212 bronze badges
1
địa chỉ cửa hàng a bình luận |
0
You should restart your Xampp or whatever hệ thống you"re runnung, make sure sq


giới thiệu
Follow
answered Apr 8, 2019 at 6:19
israelnojrisraelnojr
11
1
địa chỉ a comment |
0
I"ve had the same issue too, I didn"t remember lớn start my WAMPSERVER, và so the connection couldn"t be made...All you need to vì is to lớn start or restart your WAMPSERVER or your XAMMP again và it will work....


cốt truyện
Follow
answered Dec 27, 2019 at 11:00
Sunny Ojo Sunny Ojo
122 bronze badges
địa chỉ cửa hàng a comment |
0
All you have to do it insert you exact db details và restart your mysql server


nội dung
Follow
answered Apr 2, 2020 at 5:01
OluwatobilobaOluwatobiloba
10511 silver badge77 bronze badges
showroom a bình luận |
0
if you are using XAMPP và WAMP together in the same machine địa chỉ cửa hàng sql vps port number

1
giới thiệu
Follow
answered May 20, 2020 at 14:13
RajRaj
1111 bronze badge
add a phản hồi |
0
I had the same problem, I just deleted all log files in mysql/data files like:

mysql-relay-bin - 2020
002d...

Just these files and it worked.I hope this helps.


mô tả
Follow
edited Jun 10, 2020 at 5:01
סטנלי גרונן
2,8792323 gold badges4646 silver badges6565 bronze badges
answered Jun 9, 2020 at 19:50
MarinMarin
922 bronze badges
0
add a comment |
-1
Just restart your wamp server and then run php bin/magento cache:clean


giới thiệu
Follow
answered Jan 21, 2019 at 9:49
Muhammad AhmedMuhammad Ahmed
20533 silver badges1111 bronze badges
địa chỉ a comment |
-1
I had the same problem và I searched a lot in website but no solution worked for me .finally I noticed by chance that mysql is using port 3308 instead of port 3306 which seems to be default ,,, I changed the port khổng lồ 3306 and surprisingly it worked :) .... (my problem was in connecting php khổng lồ mysql database, php my admin page was shown perfectly)


chia sẻ
Follow
answered Aug 3, 2019 at 21:31
user11879072user11879072
1
showroom a bình luận |
-1
"dsn" => "mysql:host=localhost;port=3307;dbname=yourdbname",
cốt truyện
Follow
edited Sep 28, 2020 at 7:21
answered Sep 16, 2020 at 12:34
Mohammed AbirMohammed Abir
8933 bronze badges
3
add a bình luận |
-2
I was getting this error attempting lớn run "php artisan migrate" on Windows with a virtual box / vagrant / homestead installation.

The documentation said I had khổng lồ run this command on the virtual machine.

This worked!!!

make sure to vì it inside your current project folder.


share
Follow
answered May 23, 2017 at 7:14
educatdriskeducatdrisk
5711 silver badge44 bronze badges
1
showroom a phản hồi |
Highly active question. Earn 10 reputation (not counting the association bonus) in order to lớn answer this question. The reputation requirement helps protect this question from spam & non-answer activity.
Not the answer you're looking for? Browse other questions tagged or ask your own question.
Upcoming Events The Overflow Blog Featured on Meta
Linked
0
(HY000/2002): No connection could be made because the target machine actively refused it
-5
PHP, weird error
0
Unable khổng lồ save static data using symfony
0
what is the problem in IlluminateDatabaseQueryException?
0
PDO Exception in laravel 4.2
0
WAMP: Plugin 'FEDERATED' is disabled. #2002 mysql error
Related
426
PDOException SQLSTATE <2002> No such tệp tin or directory
70
PHP Connection failed: SQLSTATE <2002> Connection refused
0
mysqli::real_connect(): (HY000/2002): No connection could be made because the target machine actively refused it
0
WAMP, Windows 10 : #2002 - No connection could be made because the target machine actively refused it. —
1
PHP Laravel DoctrineDBALPDOException SQLSTATE <2002> No connection could be made because the target machine actively refused it
0
SQLSTATE <2002> No Connection Could Be Made
2
when I start apache MySQL server, I get error " (HY000/2002): No connection could be made because the target machine actively refused it."
1
An exception occurred in driver: SQLSTATE <2002> No connection could be made because the target machine actively refused it. - error in Symfony
Hot Network Questions more hot questions
Question feed
Subscribe khổng lồ RSS
Question feed khổng lồ subscribe to lớn this RSS feed, copy & paste this URL into your RSS reader.


default
Stack Overflow
Products
Company
Stack Exchange Network
Site kiến thiết / biệu tượng công ty © 2022 Stack Exchange Inc; user contributions licensed under CC BY-SA. Rev2022.11.15.43034


Your privacy

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device và disclose information in accordance with our Cookie Policy.

hotlive |

Hi88