MySQLi connection cannot be established, normal MySQL functions work? - php

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!

Related

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.

Troubleshooting MSSQL Connection from PHP

I'm trying to connect to an external Sql Server through PHP 5.2.
Using this line:
$con = mssql_connect('123.123.123.123','Username','Password') or die('Could not connect to the server!');
I'm receiving this error:
Warning: mssql_connect() [function.mssql-connect]: Unable to connect
to server: 123.123.123.123 in
/home/file/public_html/structure/index.php on line 4 Could not connect
to the server!
My hosting provider assures me that ports are open for my server to connect to the DB. Looking at my php info, MSSQL Support is enabled, using FreeTDS.
Any ideas why this would be failing, or how I can begin trouble shooting the problem?
i know that there is some security for remote connection to MSSQL.
i had a same issue.
you need to give connection permition for requested ip.
did you try to connect with your personal compter with a MS SQL program.
if you can so you have problem with your cilent (php host)
if you can not so you have problem with mssql server

PHP MySQL problem

Whenever I try to run a php script on my website hosted by hostgator, I get this error:
Warning: mysql_connect() [function.mysql-connect]: Unknown MySQL server host 'pieboy13_(user name)' (1) in /home/pieboy13/public_html/quigley/WebContent/Scripts/register.php on line 6
Error: Could not connect to server. Error Unknown MySQL server host 'pieboy13_(user name)' (1)
Where (Username) is my username.
What could cause this?
You are triying to connect to your username! Check your configuration for server url and make sure it points to your mysql server.
Things that can cause this:
You are using the wrong hostname for the mysql server.
Looks like you might have put your database or username into the server argument.

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.

How can I connect to MySQL on a WAMP server?

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

Categories