How can I connect to MySQL on a WAMP server? - php

This might be ridiculously easy for you but I've been struggling with this for an hour... :(
<?php
$connect = mysql_connect("localhost:8080", "root", "mypassword");
echo($connect);?>
This is the code that I'm trying to run - you can see that I'm using 8080 as my port number and, of course, I have HTML codes as well.
However, it gives me the following error messages whenever I try to open the PHP file:
Warning: mysql_connect() [function.mysql-connect]: MySQL server has gone away in C:\wamp\www\php_sandbox\index.php on line 2
Warning: mysql_connect() [function.mysql-connect]: Error while reading greeting packet. PID=4932 in C:\wamp\www\php_sandbox\index.php on line 2
Warning: mysql_connect() [function.mysql-connect]: MySQL server has gone away in C:\wamp\www\php_sandbox\index.php on line 2
I don't know... what's wrong with this? Is it because of the port number?

Change localhost:8080 to localhost:3306.

Try opening Port 3306, and using that in the connection string not 8080.

Just Change the Connection mysql string to 127.0.0.1 and it will work

Related

How do I resolve this problem? "Warning: mysqli_connect(): (HY000/1049):

Warning: mysqli_connect(): (HY000/1049): Unknown database 'art_gallery'
The database art_gallery is correctly imported and username is root, password is ``
<?php
$link=mysqli_connect("localhost","root","","art_gallery");
if(mysqli_connect_error())
{
echo "Connection error".mysqli_connect_error();
exit;
}
Normally in this type of error there are two possibilities.
First is that there are some Spelling errors.
or
Secondly you have different servers installed on your machine.
Mostly it would be due to second cause, thus to identify those servers uniquely, you have to specify the port number in the localhost when connecting via mysql connect statement
Try
mysqli_connect(“localhost:3308”,″root”,””,”dbname”) (default is 3306) it can be changed.
The port number can be checked in the phpmyadmin at top center of panel as something like server:3308
I think you can use new mysqli() function instead of mysqli_connect() function. Hope I could help you.

Unable to connect to SQL server using mysqli_connect, but MSSMS connects fine

I've read many questions similar to this but none of the answers have been relevant to me. I'm trying to access a SQL server using PHP. Both the SQL server and PHP are running on my Windows 10 machine. Here is my PHP code (the username and password are arbitrary):
$connection = mysqli_connect('127.0.0.1', 'hmuuser', 'password');
This causes the following error:
PHP Warning: mysqli_connect(): (HY000/2002): No connection could be made because the target machine actively refused it.
Here is my connection using MSSMS (which is successful):
EDIT:
I was able to solve my problem using this link: http://blog.citrix24.com/configure-sql-express-to-accept-remote-connections/
Using this link I enable SQL Browser, and set a static port to connect to SQL server with. However, I'm presented with a new error:
PHP Warning: mysqli_connect(): MySQL server has gone away in C:\HMUAPI\Index.php on line 7
PHP Warning: mysqli_connect(): Error while reading greeting packet. PID=9920 in C:\HMUAPI\Index.php on line 7
PHP Warning: mysqli_connect(): (HY000/2006): MySQL server has gone away in C:\HMUAPI\Index.php on line 7
My code has been changed to the following to cause this error: $connection = mysqli_connect('127.0.0.1:1434', 'hmuuser', 'password');
Add a database name
$connection = mysqli_connect('127.0.0.1', 'hmuuser', 'password','dbname');
Also here is suggest - Actively refused it" means that the host sent a reset instead of an ack when you tried to connect. It is therefore not a problem in your code. Either there is a firewall blocking the connection or the process that is hosting the service is not listening on that port. This may be because it is not running at all or because it is listening on a different port.
I guess the problem is, that you use MySQLi to connect to a MSSQL server.
You should use the correct MSSQL extension instead.
Microsoft published their SQL-Server for PHP driver on GitHub: https://github.com/Microsoft/msphpsql
Or you use the older extension which is documented in the PHP manual: http://de2.php.net/manual/en/book.mssql.php
And at least you can set up ODBC.
One of them should resolve your problem.

mysqli::mysqli(): (HY000/2002) localhost not working

I am trying to connect to my data base and i get an error when I use 127.0.0.1 instead of localhost.
Warning: mysqli::mysqli(): (HY000/2002): 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.
If I use localhost instead of 127.0.0.1 it works fine. Anyone have any insight into this?
the code used to connect is
<?php
$db = new mysqli('127.0.0.1', 'root', '', 'dbname');
?>
Check the sql configurations. I'm going to list a few that should be checked that could cause this option. I do recommend sharing what version of php and sql you are using. Are you using LAMP? It is the same problem listed in the above comments. Newer versions of LAMP have changed the default to 127.0.0.1 for localhost. This is why it comes across as a different problem and you do need a different approach to fix it.
1) if my.cnf has a line reading skip-networking comment it out.
2) check the ect/hosts.allow file make sure there is a line that says
mysqld: ALL
3) check the ect/hosts.deny file and make sure there is only 1 line stating
ALL:ALL
Let us know if that fixed the problem.

MySQLi connection cannot be established, normal MySQL functions work?

I'm using a MySQL 5 server and want to connect over MySQLi.
If I connect using mysql_connect, all works fine, but with MySQLi I got the following message:
Warning: mysqli::mysqli() [mysqli.mysqli]: (HY000/2005): Unknown MySQL server host 'localhost:/tmp/mysql5.sock' (1) in /XXX.php on line 129
Cannot connect to database.
On another server, MySQLi works without any problems. Any ideas?
Try localhost:3306 instead of Unix socket ?
I got the solution over Facebook!
I have to set ini_set('mysqli.default_so​cket', '/tmp/mysql5.sock'); and use just localhost as host.
Thanks anyway!

PHP & MySQL Warning: mysqli_connect() [function.mysqli-connect]: (HY000/2005): Unknown MySQL server host

Okay when I go to my web page I get the following error below but when I reload the page everything is okay and is displayed fine. What exactly is the problem and how can I fix it?
ERROR.
Warning: mysqli_connect() [function.mysqli-connect]: (HY000/2005): Unknown MySQL server host
MySQL code.
$mysqli = mysqli_connect("example.com", "avd", "password", "avd");
Server/Port combination is invalid, can't be resolved, or port is bad.

Categories