Connecting file to phpMyAdmin error - php

This problem I am having trouble with, I have been looking at it for a few hours now. So basically I am working on a registration form on my website, and while working on the php, I connected it to MySQL and Database with this line of code (which is the 6th line of code):
$mysqli = new mysqli('localhost:8080', 'root', 'mypass123', 'accounts');
I use Xampp on a Mac and when I try to register it works just not fully so, the problem is it shows this error:
Warning: mysqli::__construct(): (HY000/2002): Connection refused in /opt/lampp/htdocs/form.php on line 6
if this is not enough information, I am sorry but I am new.

PHP expects to use port 3306 for MySQL. So you need to open XAMPP, and change the XAMPP MySQL port to 3306, then restart the MySQL server.

Stop Xampp
Open xampp/mysql/bin/my.ini
Edit MySQL port to 3306
Restart Xampp
I'd say that it's already set to 3306 so just check what it's currently set to and update the setting in your PHP/phpMyAdmin to 3306 instead of 8080. 8080 is generally for the web server.

Related

Access denied While using phpmyadmin XAMPP

I have installed XAMPP on windows 10 but cannot open phpMyAdmin. I had to change Apache port 443 to 4433 because of conflicts and now both apache and mysql are running. When I click on phpMyAdmin on my server it gives me the following message in a pink box:
MySQL said: Documentation
Cannot connect: invalid settings.
mysqli::real_connect(): (HY000/2002): No connection could be made because the target machine actively refused it.
Connection for controluser as defined in your configuration failed.
mysqli::real_connect(): (HY000/2002): No connection could be made because the target machine actively refused it.
phpMyAdmin tried to connect to the MySQL server, and the server rejected the connection. You should check the host, username and password in your configuration and make sure that they correspond to the information given by the administrator of the MySQL server.
I've read the questions on similar problems but they mostly happened when someone changed the password, but for my case, the user is set to root and the password is empty both in MySQL server connection and in the config.inc.php file. I have no clue where to look for the problem.
What version is your XAMPP? Try going to task manager, locate mysqlI and end task. Now close the XAMPP window and open it again. Go to Mysql and try test the connection by connecting to the database on port 3306. If it gives en error check the error log in the XAMPP.

Problem with php and mysql connection xamp

So I am a user of windows 10 and have xammp in my computer. When I first try to run MySQL server, had problem with 3306 port because I didn't had configured ports free. So I changed it to run on port 3307 and it worked.
After that I am trying to connect to localhost/phpmyadmin, and for a reason I just can't....
Anybody have any advice/idea what is going on ?
On the xampp config file : xampp\phpMyAdmin\config.inc:
ADD THIS LINE
$cfg['Servers'][$i]['port'] = '3307';]
(I just found the answer, so... I thought would be good to leave this here.. )

Can't connect to database with error (HY000/2002): No connection could be made because the target machine actively refused it

I'm kind of new to programming and I'm only trying to connect to database using xampp but it gives me this error.
Warning: mysqli_connect(): (HY000/2002): No connection could be made
because the target machine actively refused it.
$conn = mysqli_connect('localhost', 'root', '', 'db');
I tried running the same code on a different PC and it works fine.
so i guess the problem lies within PC that I'm working on.
Any suggestions what to configure?
If you are sure that login and password are all correct, then check port number.
Default MySQL port is 3306. Maybe you've got different one on this machine.
Or, it is also possible, default port in PHP may be changed.
See XAMPP configuration to see MySQL port and add it to your server address.
PS: you may also see privileges for "localhost" connection. See 'user' table in 'mysql' database. As you have XAMPP installed, you should have phpmyadmin as well.

IIS + PHP + MySQL: A connection attempt failed because the connected party did not (trying to connect via tcp://localhost:3306)

I'm running Windows, having installed IIS 7.5, PHP 5.3 (FastCGI). Trying to connect to MySQL and getting an error "A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.".
Started to develop a project with XAMPP, but had the requirement to move it to IIS (because of AD auth). MySQL is running from XAMPP stack. I've mapped IIS to the same docroot as Apache2's, but to another port. When accessing test page server with Apache2 host - there is no problem, but when accessing IIS + PHP FCGI page - I get this error.
will the standalone installation of MySQL help?
what are your advises?
In your script, try using "127.0.0.1" instead of "localhost" as MySQL host.
If this solves your problem you can add the following line to your hosts file in /Windows/System32/drivers/etc/hosts:
127.0.0.1 localhost
After that you will able to use "localhost".
try using "127.0.0.1" instead of "localhost" as MySQL host.
Just saved my life XD XD XD

mysql_connect doesn't work on a certain host

I get this everytime I use mysql_connect() no matter what database I choose:
Warning: mysql_connect() [function.mysql-connect]: Can't connect to MySQL server on 'IP' (111) in filename.php on line 17
A MySQL error has occurred: Can't connect to MySQL server on 'IP' (111)
The exact same file works on my personal website fine. I have tried multiple databases hosted on different servers and it always gives that output.
The database itself is hosted on the same server, but using its full IP in mysql_connect(). Using localhost:port doesn't work either as it says:
Warning: mysql_connect() [function.mysql-connect]: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) in filename.php on line 17
A MySQL error has occurred: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
But using the IP should work as it has worked calling it via the same file hosted on other servers.
This is the code:
$connect = mysql_connect($db_url,$db_user,$db_pass); // connects
if ($connect == false) exit("A MySQL error has occurred: " . mysql_error());
Now since the file works on other servers i am guessing it is something to do with the server it is on and might need something changed. I don't personally have root access to the server (just my part of the shared host). Is there anything I can do i php, editing the php.ini file or something I should pass on to someone with root access?
Edit: Ok it turns out that the server doesn't have access to outside databases, so thats why the IP didn't work. Thanks for all your answers but we have decided simply to change hosting provider. We need to be able to access an outside database.
This is on a hosting service? Check their documentation, there will be something that tells you where to find mysql. It isn't necessarily localhost.
For example, on startlogic.com, you use: yourdomain.startlogicmysql.com
Can you connect using mysqladmin using the same host, username and password?
mysqladmin -h $db_url -u $db_user -p $db_pass
Replace $db_xxxx with real values.
If that works from the same host as your php script, then sudo to the apache User and try the same test. One of those must be failing.
EDIT: nevermind on sudo part, I noticed that you don't have root access.
Something else to try: Use '127.0.0.1' instead of 'localhost'. I have had issues before where mysql stupidly assumed it could silently change 'localhost:' to '/var/run/mysqld/mysqld.sock'.
Your wording is not very clear, I hope you are not thinking you can connect to the same mysql server from any old web server just because you know the IP address and port number. If the web host is at all competent, they have probably firewalled mysql so it is only accessible through their own web servers.

Categories