error to connect database, target machine actively refused it - php

I'm developing an application, in which two tables of a database are connected but not the third. (This is on server. They are working fine on my local machine.)
1. Warning: mysql_connect() [function.mysql-connect]: [2002] No
connection could be made because the target machine actively (trying
to connect via tcp://localhost:3306) in D:\Hosting.. on line 5
2. Warning: mysql_connect() [function.mysql-connect]: No connection could be made because the target machine actively refused it. in D:\Hosting.. on line 5
At an earlier stage, I connected to the two tables from the same database successfully, so I've checked the physical location of each table of the database. No wonder all are physically resting at the same place in the database.
Please help me to understand the problem.
EDIT :
//Page1 has something like:
$conid=mysql_connect("dxxs.db.7xx7.hostedresource.com","dxxs","Kxx3") or die();
mysql_select_db("dxxs",$conid) or die();
mysql_query(“some basic 4-5 queries depending on user’s interaction with table1”);
mysql_close($conid);
//redirection to page2 from there to page3
$conid=mysql_connect("dxxs.db.7xx7.hostedresource.com","dxxs","Kxx3") or die();
mysql_select_db("dxxs",$conid) or die();
mysql_query(“some basic 4-5 queries depending on user’s interaction with table2”);
mysql_close($conid);
//some redirection to page4
$conid=mysql_connect("dxxs.db.7xx7.hostedresource.com","dxxs","Kxx3") or die();
mysql_select_db("dxxs",$conid) or die();
mysql_query(“some basic 4-5 queries depending on user’s interaction with table3”);
mysql_close($conid);
Now my problem is when connecting to table 3, the server is throwing an error as
stated above
Where in line 5, MySQL_connect is written. Please help me to understand why table 3 is not getting connected whereas table 1 & table 2 are able to connect. All are resting at the same database on the server.

It sounds like you are calling mysql_connect() once for each table you are working with. You do not need to do this - you only need to connect once for each server you are working with.
The server is probably limiting you to 2 concurrent connections, which is why it is refusing the third.
Try calling mysql_connect() once at the top of your script.

I have found the issue and solved it. Try to use my code using port after hostname:PORT:
$dbh=#mysql_connect('dbxxxxxx.db.1and1.com:3306','db-username','db-password');
if (!$dbh) {
$err_msg='Cannot connect to the database because: '.mysql_error();
}

Related

Unable to connect Website to my phpmyadmin MySQL database

Before I get into the question, I ran into a lot of questions, both on this website, as well as a bunch of others, however none of the solutions there helped, and so decided to post a question with my exact situation.
So I am currently building a website, and am trying to connect it to a MySQL database I have created on phpmyadmin through hostgator. I am currently using 000webhost.com to host my webpages, as the computer I am working on does not have an ftp client, and am unable to install it as of now. As such, I decided to upload the files onto there temporarily as I build it, as they are dynamic webpages. Whenever I load up the page, however, I receive this error:
Warning: mysqli_connect(): (HY000/1045): ProxySQL Error: Access denied for user...
where the "..." just lists my username and filepath to the file.
this is my php code to connect to the database:
<?php
define("DB_SERVER","localhost");
define("DB_USERNAME","**user**");
define("DB_PASSWORD","**password**");
define("DB_DATABASE","**database_name**");
if(!mysqli_connect(DB_SERVER,DB_USERNAME,DB_PASSWORD)){
echo"Failure";
}
else{
echo"Success!";
}
?>
I double- and triple-checked the database username, password and name, however to no avail. Thanks a lot in advanced!
You have to change your DB Server location due to you are not using the same web server as your hosting.
Change this
define("DB_SERVER","localhost"); to define("DB_SERVER","YOUR_REMOTE_DB_SERVER");
Also you have to enable remote access in your mysql database.
You can check this similar topic
To answer your initial question, there is no call to connect.
define("DB_SERVER","localhost");
define("DB_USERNAME","**user**");
define("DB_PASSWORD","**password**");
define("DB_DATABASE","**database_name**");
$conn = mysqli_connect(DB_SERVER, DB_USERNAME, DB_PASSWORD);
then test your connection.
As for setting up a localhost for development, if you are using Windows I would suggest XAMPP, it is pretty much download and say yes to all.

mysql_connect() causing web page to crash

I am currently running an amazon EC2 instance to host my website. I am trying to connect to the MySQL database.
I have code ...
<h1>Test page</h1>
<?php
$connection = mysql_connect("xxx.xxxx.us-west-2.rds.amazonaws.com","username","password");
?>
An attempt to load this web page will cause an infinite loading symbol. It is as if an infinite loop is running. Here are some details ...
The page will load if i remove the mysql_connect() function
The page will properly display all php data including all other functions.
The "host","username" and "password" arguments are correct and the MySQL database server is running. I know this because i can connect and manipulate it through Sequel Pro.
The page will load if i modify the "host" argument to something incorrect.
Feel free to ask questions. Thanks.
EDIT: After waiting about 90 seconds, the page will eventually load and display error 2002.
Try using:
mysqli_connect()
instead of
mysql_connect()
So maybe this server only supports mysqli.
I'm not sure what else to try if everything else is right.
This means that the server is not responding to the request you sent and so mysql connection is not being established. Try using another server.

PHP and SQL - Database overload

I'm building a web app that uses lots of requests to my database. Every thing was working perfectly smooth until a half an hour ago when the requests weren't returning... I checked the PHP file directly and it displays the following:
<br />
<b>Warning</b>: mysql_connect() [<a href='function.mysql-connect'>function.mysql-connect</a>]: Too many connections in <b>/home/sanity/public_html/dev/forest/js/database.php</b> on line <b>7</b><br />
Unable to connect to MySQL
So I figured let's check phpMyAdmin, but it's not showing me ANYTHING except for a big red box that says:
SQL query: Edit Edit
SET CHARACTER SET 'utf8';
MySQL said: Documentation
#1045 - Access denied for user 'root'#'localhost' (using password: NO)
Between the last time it worked and now I haven't changed any configurations or code.. How do I begin to fix this?
Could this be caused by the fact my PHP files don't close the connection after using it? If so should I be closing the connection after every query? I figured the connection would close automatically when the user leaves the web site.
EDIT: The requests are sending through now and phpMyAdmin is back up, but how do I prepare this site for heavier traffic?
When I started my job, one of my first tasks was to continue working on what one of the directors had started coding. In his code, I saw this monstrosity:
function getTicket($id) {
mysql_connect("localhost","username","password");
mysql_select_db("database");
$sql = mysql_query("select * from tickets where id = ".intval($id));
return mysql_fetch_assoc($sql);
}
In other words, he was creating a whole new database connection every single time he wanted something from the database, and never closing any of them (instead letting them be closed at the end of the script automatically)
This was fine for basic testing, but as soon as I started writing more advanced stuff (before I'd discovered this piece of code) things majorly screwed up with the same "too many connections" error as you.
The solution was simple: restart the server to clear all pending connections, and fix the code to only connnect once per script execution.
This is what you should do. There should only ever be one call to mysql_connect (or indeed any database library's connect function) in your script (and I don't mean in a function that gets called several times!)
You should also check the database's configuration, just in case someone accidentally set the maximum connections too low, but generally this shouldn't be a problem if you manage your connections properly.
Though the mysql_* functions are deprecated (use a modern driver like PDO for instance), you should take a look at the mysql_close($con) function.
Here is the doc.
EDIT
If you are not using mysql_pconnect function, then your connection should be closed at the end of the execution of your script.
Apparently, one reason for such error is shared hostings. If you are using a shared hosting, generally speaking, the maximum connections to the server allowed by the hosting is not the greatest.
If you can change the max_connections system variable then try to change it to a greater number:
max_connections = 200

MySQL No Route to Host, mysqli_connect(): (HY000/2002)

I am trying to install BugZilla on Mac OS X 10.9 (Mavericks).
I'm hitting a snag with my MySQL configuration.
I have installed MySQL from the DMG Image mysql-5.6.14-osx10.7-x86_64
MySQL seems to be installed and running ok.
I have created a user called bugs, and a database called bugs.
I confirm that I can login to MySql from the terminal command line, using the bugs username and password, and access the bugs database.
However the installation of BugZilla fails with an error connecting to MySQL. I tried a simple test and wrote this php file:
<?php
// Create connection
$con=mysqli_connect(“localhost”,”bugs”,”********”,”bugs”);
// Check connection
if (mysqli_connect_errno($con))
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
?>
But it fails at line 3 with:
Warning: mysqli_connect(): (HY000/2002): No route to host in /Users/bugzilla/Sites/test_my.php on line 11
Failed to connect to MySQL: No route to host
Why is it that I can connect from the command line, but not from php?
We experienced this error because the ip subnet used by our vagrant environment was the same as the subnet of the database server. We needed to recreate the database server on a different subnet.
I just experienced a similar problem but through which it looks like there was a different problem case. I was getting the same error:
Failed to connect to the database, please check your credentials: No route to host
And we were able to figure out the problem was actually that the disk space of our database was full (our server administrator was out sick for a while, and we automatically make snapshots, but only manually delete them on a regular basis. After a few days, the snapshots took up the space of the entire server and rendered it unresponsive).
I don't know if this will be the answer to anyone with this issue, but if someone does stumble upon this same error, hopefully this might help.

Database Connection Failed

While I am browsing my online app in the server I got an error like
Database Connection Failed
User coule_com#c17564 already has more than 'max_user_connections' active connections.
But this is working well in my local system. And this error occurs ANY TIME when I navigate in the server. If i refresh the browser i can able to move further. But I in need to solve this issue.
will anybody help me to solve this issue ?
connection code :
function makeConnection() {
global $config;
$this->ConLink = mysql_pconnect($config['DBHostName'],$config['DBUserName'],$config['DBPassword']) or die("Database Connection Failed". mysql_error());
mysql_select_db($config['DBName'], $this->ConLink);
return true;
}
Are you closing the connections when you're done with them?
If not, then I would assume there's lots of database connection objects lying around just waiting for GC to pick them up, and until it does, you risk running out of available connections.
you need to contact your host and get them to up the connection limit. if they won't, you need to find a better host. this is simply a fact of life in web-based applications.

Categories