Hi I'm running Windows 8 64bit, wamp 3.1.3 32bit, Apache 2.4.33, PHP 5.6.35, MySQL 5.7.21, and MariaDB 10.2.14
I'm building a login system and in the last 24 hours I have started to receive an ERROR MESSAGE =
Connection failed: SQLSTATE[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.
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
Query
+-+-+-+-+-+-+-+-+-+--+-+-+-+-+-+-+-
I am using WAMP without issue for approx 5 months. I am using localhost with MySQL on a live (.IE Irish domain).
Until 24 hours ago eEverything worked OK. Now, all attempts from the localhost to connect to MsSQL fail (e.g. to search the DB for a user and verify a password).
However, if I FTP files to my domain the connection is OK and a successful connection is made to the DB.
I have read all other entries around this and similar issues. It seems quite common and (to the extent that I can understand the other replies) I cannot find a solution:-
So far I have tried:-
- Searching form.wampserver.com, Stackoverflow and youtube.
- I disabled Avast (my antivirus),
- I checked the c:...host file (it only has 5 lines),
- I do not think that any system changes have been made to my pc,
- I have not installed any new software,
- I've tried 127.0.0.1 instead of localhost,
- I've checked to see if port 3306 is available (I think it is but I'm new to this and cannot be sure I have done this correctly).
Below is a sample of a file I created to test the connection:-
(PS I know mysql is depreciated - but this was written only to test the connection!)
(PPS Obviously I've removed the real name/pw/host, etc)
<?php
$dbname = 'dbname';
$dbuser = 'username';
$dbpass = 'password';
$dbhost = 'dbname';
$connect = mysql_connect($dbhost, $dbuser, $dbpass) or die("Unable to
Connect to '$dbhost'");
mysql_select_db($dbname) or die("Could not open the db '$dbname'");
$test_query = "SHOW TABLES FROM $dbname";
$result = mysql_query($test_query);
$tblCnt = 0;
while($tbl = mysql_fetch_array($result)) {
$tblCnt++;
#echo $tbl[0]."<br />\n";
}
if (!$tblCnt) {
echo "There are no tables<br />\n";
} else {
echo "There are $tblCnt tables<br />\n";
}
?>
Any attempt to connect to MySql from wamp/localhost generates the error. But if the file is FTP'd to a real domain it successfully connects and prints the number of tables in the DB (which is 6). Therefore, there are no mistakes in the url/db/username/pwd, and I don't believe there are any changes with PHP/MySQL set up on my domain.
Also as the file works when put on a live server, the username/pw, db, etc are all correctly spelt.
Finally, I have been saving different versions of my website in development. Each of the last 6 versions have worked without any issue. Now none of the earlier versions of the login system work. This means that I can rule out any mistake made in the recent version of the website.
I'm a newbie and I'm stuck. I hope not to get roasted if this in fact turns out to be a repetition of another question/response. I have done my best to find an answer before posting this.
Any help would be Greatly appreciated...
Related
I've migrated a Database from cPanel to cPanel through Backup tool, But the problem is whenever i try to connect to this database for example using this TEST php code
<?php
# Fill our vars and run on cli
# $ php -f db-connect-test.php
$dbname = 'imadoulh_test';
$dbuser = 'xxxxx';
$dbpass = 'xxxxx';
$dbhost = 'localhost';
$connect = mysql_connect($dbhost, $dbuser, $dbpass) or die("Unable to Connect to '$dbhost'");
mysql_select_db($dbname) or die("Could not open the db '$dbname'");
$test_query = "SHOW TABLES FROM $dbname";
$result = mysql_query($test_query);
$tblCnt = 0;
while($tbl = mysql_fetch_array($result)) {
$tblCnt++;
#echo $tbl[0]."<br />\n";
}
if (!$tblCnt) {
echo "There are no tables<br />\n";
} else {
echo "There are $tblCnt tables<br />\n";
}
the response is This page isn’t working with HTTP ERROR 500
and the MySQL log says Got an error reading communication packets
I did try many ways to fix it but unfortunately.
Here's what I tried:
1. optimize and repair tables
2. add some code to /etc/my.conf file such as
max_allowed_packet=2684354569944
open_files_limit=10000
default-storage-engine=MyISAM
innodb_file_per_table=1
default_authentication_plugin=mysql_native_password
dealing with this article:
https://dba.stackexchange.com/questions/19135/mysql-error-reading-communication-packets
Error 500 from http means your web program -- your php program -- failed trying to send out that page. But 500 can tell us absolutely nothing about why it failed. So, moving along... You seem to be getting communication errors between php and mysql.
I believe the key words in your question are from cPanel to cPanel. That suggests you are migrating your application from server to server and maybe even from hosting-vendor to hosting-vendor.
You have imported your MySQL data from backups onto a new server with a different IP address. So, you now have two different database instances. And, it's possible you have two different instances of your php program.
So now you're troubleshooting these questions:
Can my new php code talk to my new database server? From your question it's hard to tell whether the answer is "no" or "sometimes, but unreliably."
Does my new php code run at the same hosting vendor as its MySQL database? In network engineer lingo the question is "are they on the same datacenter network?"
Is there any chance I'm trying to hit the new database from the old code, or the old database from the new code?
Some (but not all) technical support specialists at hosting companies know about this kind of thing. Call for help, but be sure the first two words out of your mouth are "I'm migrating" so they know it's a new customer and a one-time setup issue.
I have been searching for an answer for last 3 days before posting.
I have installed SQL Server 2012 and, Apache24, PHP7.0
The Apache started fine, PHP7 Started fine
I can browse localhost/info.php and it shows perfect
Installed ODBC
Installed the SQL extensions drivers
Configured PHP.ini and apache conf file
SQL services started through SQL configuration manager
also allowed in the network configuration the TCP\IP and named pipes
I can't login to the SQL server using Microsoft SQL server manager
So all seems to be fine but every time I try to do a simple PHP code to connect my PHP to the SQL server I get the below error
Warning: mysqli_connect(): (HY000/2002): No connection could be made
because the target machine actively refused it. in
C:\Apache24\htdocs\index.php on line 13 Could not connect
Have disabled the firewall also and even added a rule with few ports
I am running on windows 10 Enterprise
Also when I change the server name to WALEED\SQLEXPRESS I get the below
Warning: mysqli_connect(): php_network_getaddresses: getaddrinfo
failed: No such host is known. in C:\Apache24\htdocs\index.php on line
13
Tried to search in the SQL server log but couldn't find any errors
All extensions for my PHP are working fine on info.php
Index file :
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
$dbhost = 'localhost';
$dbuser = 'admin';
$dbpass = 'admin2017';
$db = 'sunto';
$conn = mysqli_connect($dbhost,$dbuser,$dbpass,$db);
if(! $conn){
die('Could not connect') ;
}
echo 'Successfully Connected';
$sql = 'Connected Successfully';
$retvalue = mysqli_query($sql);
if(! $retvalue){
die('Cannot connect to SQL: ');
}
echo 'DataBase test_db13 has successfully created';
mysqli_close($conn);
?>
In the comments you said:
what is strange when i Try to connect with sqlsrv_connect(
"localhost", $connectionInfo ); it is fine connected but when i try to
connect using mysqli. it shows error
There's nothing strange about that. The clue's right there in the name of the method you're using:
mysqli_connect()
That code library is for connecting to MySQL databases only.
You need to use the sqlsrv_ library instead if you want to connect to SQL Server. They're completely different database platforms, with completely different PHP libraries to use for working with them. As you saw yourself, it works when you use sqlsrv_connect.
I'm not really sure why you then tried to use mysqli after that, or why you expected that to be successful.
As the title indicates I'm trying to link my MySQL database to my website using php.
I'm using GoDaddy hosting for the MySQL database and I got this code directly from them and it's still not working for some reason, giving the error below.
Here's my code :
<?php
$hostname = "trdlibrary.db.6253425.hostedresource.com";
$username = "*******";
$password = "*******";
$dbname = "trdlibrary";
$connect = mysqli_connect($hostname, $username, $password, $dbname, 3306) OR DIE ("Unable to connect to database! Please try again later or contact an administrator for help.");
?>
Here's the error :
Warning: mysqli_connect(): (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. in C:\xampp\htdocs\searchengine\dbconnect.php on
line 6 Unable to connect to database! Please try again later or
contact an administrator for help.
Can anyone see the issue?.. or is this something I need to contact GoDaddy's support line about.
-- EDIT --
I forgot to mention that I am running the web server off my local machine using XAMPP (so I can run the PHP scripts) but the MySQL server is off-site with GoDaddy, so 'localhost' won't work currently.
-- EDIT #2 --
So I learned that sadly, remote access of MySQL databases to GoDaddy requires a more expensive and 'higher tier' hosting package from them. So I just answered my own question, thanks to those who replied.
You have to setup remote access to databases on Godaddy. You can refer to this page to see how to enable it.
I'm a little bit frustrated with a problem I'm having in a system migration from AWS to GCE.
I've an ec-2 instance running on amazon web services, perfectly working and configured.
The problem is that google is offering a 100.000$ credit in a special plan for Startups, my company's CEO asks for a migration, so here I am.
I have all running and almost fully configured in a ubuntu 14.04 LTS instance, I said almost, because I can't achieve a simple task such as connect to a Mysql db :(, and I think I'm missing something in someplace and my mind gets offuscated, so I need your help.
First of all, I only having this problem on remote server, I've tested it like a hundred times in local, and of course in aws, where it is currently in production state, so I have no clue what or where exactly the problem is.
My GCE config:
OS: Ubuntu 14.04 LTS
HHD: 30GB persistence ssd disk
CPU : 2x
RAM : 7,5 GB
Zone: europe-west1-c
Static Ip
So, I installed Lamp and phpmyadmin, all works like a charm. I disable root access from remote clients to Mysql db, configured php and apache modules.
The Web app is a Rest Api, based on PHP(Slim), that, like I just said, is now working on AWS.
When I call to and endpoint that doesn't need to retrieve any data from the db, it works well, the problem comes when the endpoint called try to access the db. In that case the request never respond, it keeps loading forever until I abort the request. It is kind of weird, because I can manipulate all the data through phpmyadmin, which access to the db the same way mysqli does.
If I checked the logs, nothing is printed on them. Only when I change the "locahost" host param, it prints a log saying: "No mysql db on XXX.XXX.XXX.XXX"(IP).
config.php File
define('DB_USERNAME', 'user');
define('DB_PASSWORD', 'pass');
define('DB_HOST', 'localhost');
define('DB_NAME', 'db_name');
DbConnect.php
function connect() {
include_once dirname(__FILE__) . '/Config.php';
// Connecting to mysql database
$this->conn = new mysqli(DB_HOST, DB_USERNAME, DB_PASSWORD, DB_NAME);
// Check for database connection error
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
/* change character set to utf8 */
if (!$this->conn->set_charset("utf8")) {
echo "Error loading character set utf8: " . $this->conn->error;
}
// returing connection resource
return $this->conn;
}
loops forever img
Expected Response img
Any help is welcome!
Have you changed the bind-address parameter in the my.cnf MySQL config file? This has caught me a few times. MySQL by default in Ubuntu 14.04 will only listen on localhost and will ignore remote connections.
Also, check out the answer to this question and it might give you some help as well: Remote Connections Mysql Ubuntu - bind address failed
I have a database set up on a godaddy server. It is configured to allow remote access, and there are a couple of websites I'm running which need to access this data. It works when accessed from another godaddy site, and I can connect from my development environment both at work and home. We recently set up hosting with mydomain.com.
Here is the code block that triggered it:
function connect(){
$servername = "XX.XX.XXX.XX";
$dbusername = "databaseusername";
$dbpassword = "mahpassword";
$dbname = "databasename";
try{
$newMysql = new PDO("mysql:host=".$servername.";dbname=".$dbname, $dbusername, $dbpassword);
}
catch(PDOException $e){
echo 'connection Failed: '. $e->getMessage();
die;
}
}
and now I'm getting this error message on the new site:
connection Failed: SQLSTATE[HY000] [2003] Can't connect to MySQL server on 'XX.XX.XXX.XX' (111)
The only problems I can think of is that either for some reason there are a limited number of IP addresses the MySQL database will connect to by default (which seems squirrely), I'm getting blocked by a firewall on the MySQL server (again.. doesn't make sense to me), or there is some setting on the mydomain hosting server disallowing remote requests (?)
I'm new to this kind of thing, so I'm open to any suggestions. I could probably just set up another database on the new site, but I don't want the hassle of keeping them synchronized if I don't need to. What might be wrong? Are there any workarounds?
[edit]
connected to remote database via console (mysql -h XX.XX.XXX.XX ...), the privileges were found under the information_schema database, a quick select * from SCHEMA_PRIVILEGES and select * from USER_PRIVILEGES shows that 'databaseusername'#'%' has sufficient privileges. Not that it helped me any, but maybe it'll help someone down the road.
[/edit]
As it has been more than a year since I asked this question, I suppose I need to answer it just to close it.
It turns out that godaddy had blocked mydomain.com servers via firewall ("Remote access" was limited). so in order to accomplish what I wanted to do, I had to copy and store the database on both sites.