I have two application in one domain
1) In java and having phpmyadmin/mysql database.
2) In php5.3
I am try to connect first application database using second application.
but its not possible.
return error.
Failed to connect to MySQL: Can't connect to MySQL server on '127.13.153.130' (113)
here is my code to connect phpmyadmin database.
<?php
// Create connection
$con=mysqli_connect("127.13.153.130","adminz6RCQ***","zs4-EbW-****","testjaphp");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}else{
echo "connected";
}
?>
Help me if I can do this.
thanks.
Your Java Application needs to be a scalable app so your mysql database is put on its own gear. Once its scalable it will have an externally accessible address that you can use to connect to. Simply clone your app to scalable app see here and then check your environment variables to see what your new address is.
Related
I am having a huge issue with accessing my AWS database from within the php code for a site i am building. I have tried many different connection methods, and all seem to give an error that says
Warning: mysqli_connect(): (HY000/2003): Can't connect to MySQL server on '(the endpoint of my hosted DB)' (111)
I've looked up error 111, but I can not seem to understand why it applies to me in this scenario. I can access my database from any computer, using the same information I'm using here to try to connect. I'm starting to think it's the host I'm using for my site that's the problem. I'm using the free biz.nf host just for testing, but I'm not sure my site host really should have any effect on the php inside my site. Here's my connect statement
$mysql_host="DB endpoint";
$mysql_user="myusername";
$mysql_pass="mypassword";
$my_db="myDBname";
$con = mysqli_connect($mysql_host,$mysql_user,$mysql_pass);
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
Thanks for the help!
You likely need to update your security group and route tables for your subnets to allow the host on biz.nf to access the RDS instance.
Check your RDS dashboard for the given instance, and examine the settings on your security group and subnets.
I wrote a simple user registration system that runs on my local machine using apache. (Localhost at port 8080).
My php file that tries to connect to mysql database looks like :
<?php
$con = mysqli_connect("localhost","root","","register");
//localhost will have to change to host name if hosted on different server... I think.
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
?>
Everything works and I can register/sign in a user on my local machine.
I know that I have to change $con = mysqli_connect("localhost","root","","register"); once I am ready to upload my site to host it in a free server like surge.sh or github pages.
I pushed my site to github pages from my repository and when I click "Register" / "Sign in" it doesn't load the page instead it acts as if I want to download the .php file. How should I make the changes? I need some help and suggestions.
This sounds like a stupid question, but I'm beginning in PHP and MySQL and failing at the first step, trying to connect to the database:
<html>
<head>
</head>
<body>
<?php
$con = mysqli_connect("localhost", "root", "root", "ASOIAF.odb");
if (mysqli_connect_errno()) {
echo "Failed to connect to database";
} else {
echo "Connected to database";
}
mysqli_close($con);
?>
</body>
</html>
I don't understand the first host parameter. A yahoo help page said that the host should be "mysql", but when I used this it failed to connect as well. The database, ASOIAF, is in OpenDocument database format (odb), on LibreOffice Base. I'm using Uniserver to run PHP and MySQL; both are currently running. The web application is stored in Uniserver's www folder, and run on Google Chrome through localhost.
What should I be inserting in the host portion of the connect statement? Or have I made a more basic syntax error in the PHP code that is preventing a connection from being made?
What is my host name for MySQL?
We don't know what you have called the computer you are running MySQL on.
A yahoo help page said that the host should be "mysql"
That is specific to Yahoo Web Hosting. It doesn't sound like you are using their service, so that is inapplicable.
I'm using Uniserver to run PHP and MySQL
That suggests the computer running the webserver running PHP and the computer running the MySQL server are the same machine. That makes localhost appropriate.
localhost is the standard name given to a computer on the private network that only it connects to. For MySQL is has a special meaning and causes the connection to be made via a socket instead of TCP/IP (which is more efficient).
What should I be inserting in the host portion of the connect statement?
localhost if the above is correct.
Or have I made a more basic syntax error in the PHP code that is preventing a connection from being made?
I can't see any syntax errors. I suspect the problem may be down to your database configuration. Have you told the MySQL server about ASOIAF.odb? Is that what the database is actually called inside MySQL (as opposed to just being the file that stores the configuration for LibreOffice to connection to that database).
Your biggest mistake is not using mysqli_error to find out what problems PHP is reporting.
if (mysqli_connect_errno()) {
echo "Failed to connect to database";
echo mysqli_error();
use
mysqli_connect("localhost", "root");
Hope it will work
I am running an apache webserver on a server on my local network.
I have a microsoft SQL server 2008 r2 database running on a different machine on the same network. My webserver is hosting a lot of pages, and are all fine and can be accessed locally and externally. However, when I try to connect to the SQL database using php, I get hit with the following error.:
Failed to connect to MySQL: No connection could be made because the target machine actively refused it.
I am at a total loss at this point as I have opened port 1433 and have spent hours trying to figure this out.
The code that I am using is a very basic connect script:
<?php
// Create connection
$con = mysqli_connect("mycomputer", "myname", "password", "my_db");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
?>
If anyone can help, I would sincerely appreciate it as iIam about to give up on this project!!!
Thank you in advance.
As i understand - you use MS SQL , so you must use mssql_connect not as mysqli_connect
Check here
Cause its another database and another driver (extension ) using to connect
I've newly set up a VPS and installed WHM.
I have a MySQL DB on this server which I am able to connect with using a desktop SQL application called Sequel Pro.
Using PHP I have set up a subdomain which I want to connect to this DB, I have used the same details as the Desktop Client but I keep receiving PHP Warning: mysqli::mysqli(): (HY000/2003) messages in my PHP error_log.
I'm completely stumped as I thought I would be able to connect to the DB from another website. I have add % to the cPanel Remote MySQL® and still no luck.
Could someone please point me in the right direction.
<?php
$mysqli = mysqli_connect("HOST_IP","DB_USER","DB_PASS","DB_NAME");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$q = $mysqli->query("SELECT COUNT(*) FROM users");
print_r($q);