my connection string is:
$connection = mysql_connect("localhost", "root", "") or die("Could Not Connect to DB: ".mysql_error());
but on my computer i have installed IIS server first so localhost:80 is reserved by it so I changed my port to 8080 changing httpd.conf file in apache folder.
Now what should I change in connection string to connect to my database.
I am using XAMPP .
should I tried writing these:
1:
$connection = mysql_connect("localhost:8080", "root", "") or die("Could Not Connect to DB: ".mysql_error());
2:
$connection = mysql_connect("localhost,8080", "root", "") or die("Could Not Connect to DB: ".mysql_error());
But Not working Help please.
Thank You
Default port number which Mysql server uses is 3306
Web servers default port is 80
Web server and Mysql server are independent.
Do not change your api to connect to your mysql
Related
I was trying to use php to remote connect to MSSQL database in other server. But at the end it show error
Warning: mssql_connect() [function.mssql-connect]: Unable to connect to server: xxx.xxx.xxx.xxx in xxxxxxx
Here is my code
<?php
$myServer = "xxx.xxx.xxx.xxx";
$myUser = "user";
$myPass = "password";
$myDB = "database";
//connection to the database
$dbhandle = mssql_connect($myServer, $myUser, $myPass)
or die("Couldn't connect to SQL Server on $myServer");
//select a database to work with
$selected = mssql_select_db($myDB, $dbhandle)
or die("Couldn't open database $myDB");
?>
I have try the login with microsoft SQL Server Management Studio and it can work and login so I don't that having problem with the allow remote connection access.
Btw.. I just access it from XAMPP Localhost. I'm not sure is this effect or not.
Thank you in advanced for whose help.
First guess:
Your SQL-Server is not listening to TCP/IP. Enable that protocol in configuration manager. Restart the server process.
Second guess:
A firewall is blocking the access. Enable access to TCP Port 1433.
Third guess:
driver problems
mssql driver need that special version of the ntwdblib.dll.
Depending on you php version it's not there.
Better switch to the new driver "sqlsrv".
https://www.microsoft.com/en-us/download/details.aspx?id=20098
I'm cant connect to PostgreSQL with php code. My Postgresql is docker container.
I get an IP with:
docker inspect toshi_db_1
How I'm trying to connect:
$dbconn = pg_connect("host=172.17.0.2 port=5432 dbname=toshi_development")or die("Could not connect");
Error: Warning: pg_connect(): Unable to connect to PostgreSQL server:
could not connect to server: Connection timed out (0x0000274C/10060)
Is the server running on host "172.17.0.2" and accepting
TCP/IP connections on port 5432?
I thought there could be problems in PostgreSQL.conf with listen_address configuration parameter, but it allows all connections, so I have no idea where the problem is.
UPDATE: I fixed it myself, just tried to expose wrong port in
docker-compose file.
I run in the same situation today. The solution was replacing the localhost port with the name of the container. Like:
$dbconn = pg_connect("host=toshi_db_1 port=5432 dbname=toshi_development")or die("Could not connect");
Not sure if it should be the same with IPs. But doesn't the IPs change?
So, for other people seeing this post: remember that 127.0.0.1 always points to current container. So you must replace that "localhost" part with your container name.
This question already has an answer here:
SQLSTATE[HY000] [2002] A connection attempt failed.. - When attempting to connect from Local to remote server
(1 answer)
Closed 3 years ago.
I am trying to connect to a remote server database using PHP code (mysqli)
$host = 'myIP:3306';
$user = 'root';
$pass = 'pass';
$conn = mysqli_connect("$host", "$user", "$pass");
//check connection
if (mysqli_connect_errno())
{
echo "Error: " . mysqli_connect_error();
}
I used myIP/phpmyadmin to make a database and i used putty to check if mysql was running correctly. I also checked the default port for mysql on my server, which was the default (3306).
The error given is described as either a connection fail/time-out/no response.
I also tried using PDO instead of mysqli but it gave me the same results. All other examples i could find where about localhosts and the solution given in those posts is using the socketpath to connect (which doesn't seem like a solution for me as it's remote..).
It's a linux server provided by school.
Any ideas? Thanks in advance.
With mysqli_connect(), you can use 6 parameters:
host, username, password, dbname, port, socket
Host and Port are separate.
Try using:
$conn = mysqli_connect("myIP", "$user", "$pass", "dbname", "3306");
Also, the default port is 3306 so you probably do not even have to provide it.
I have a system in Bluehost which I could connect easily to the database with
$con = new_mysqli("localhost", "username", "password", "database");
But I'm also trying to establish a second connection, but not in the Bluehost, but in a local server we have. So we created an outside IP for it so we can access the MySQL database that it has.
I try to connect it with this:
$con2 = new_mysqli("XXX.XX.XXX.XX", "root", "", "database");
But it only returns this error.
Connect failed: Can't connect to MySQL server on 'XXX.XX.XXX.XX' (110)
Why am I not connecting? Is there a configuration that I miss out?
You can comment for further details that I might have missed.
there's this server:
http://phpmyadmin.pvdata.fr/index.php ,
I can connect to it knowing the username and password and Server Choice.
Once I connect to it, it shows under MySql the following information: (I'm Translating from French)
Server: sql6 (sql6 via TCP/IP)
Server Version: 5.0.92-87
Protocol Version: 10
Username: pvdata#10.5.1.3
Character for MySql: UTF-8 Unicode (utf8)
So I tried using the following code in order to connect to the Database:
<?php
// Create connection
$username = "pvdata";
$password = "xxxxxxxx";
$hostname = "10.5.1.3";
$dbhandle = mysql_connect($hostname, $username, $password)
or die("Unable to connect to MySQL");
?>
But it didn't work, it's saying: "A connection attempt failed because the connected party did not properly respond after a period of time".
What am I doing wrong?
Go to your phpMyAdmin installation and look for the file config.inc.php. Open that file, and check which hostname / ip is being used for SQL6. That is the IP you should use for your mysql_connect()
This is most likely a firewall issue. Most 3rd party hosts don't allow you to access MySQL from 'the outside'.
You can do this if you manage the MySQL server yourself or if you have a host that doesn't deny you to access the database from another machine, but in regular web hosting, this is not common.
You need to search, google helps a lot, also you need to connect to an ip/domain and port of your MySQL server.
For this, you need to know what is the port of your mysql server.
Look this answer from link
<?php
mysql_connect("mysite.com:3306", "admin", "1admin") or die(mysql_error());
echo "Connected to MySQL<br />";
?>
to check if you have coneccion, try in console:
shell> mysql --host=remote.example.com --port=3306 //3306 is the
defaul port for MySQL
http://dev.mysql.com/doc/refman/5.0/en/connecting.html