PHP call to MYSQL INSERT is HANGING - php

IS there any logs on the MySQL server in regards to access? I am having an insert statement hang. It could be a subnet/firewall/interface configuration problem. I have the firewall open for the MySQL traffic, but it appears to be being blocked on an irregular basis. Sometimes it works and sometimes it doesn't. Any ideas for places to start looking in my logs?

To troubleshoot your query, grab a front end like SQLyog or MySql Workbench. You can run your queries in it and more directly interact with the database to see if the query itself is throwing the error.
If you're having a connection problem of some sort, the error message in your php app should provide some hints (timeout, server not available, etc.).
Next, you can enable error messages in PHP by changing settings in your php.ini, or adding a command in the script itself, see http://www.php.net/manual/en/book.errorfunc.php.
Finally, MySQL can log errors, but where it does and whether it does depends on your particular installation. Check your MySQL configuration file to see if error logging is enabled and to what location it outputs.
Post the error message you are getting if you need additional help.

Related

mysqli over ssl giving 2003

I'm using mysqli connection over ssl,
so using in code following:
$mdbconnection = mysqli_init();
$mdbconnection->ssl_set('/ssl/xyz.pem', '/ssl/abc-cert.pem', NULL, NULL, 'AES256-SHA');
$mdbconnection->real_connect(SV_SERVER, SV_MYSQL_LOGIN, SV_MYSQL_PASSWORD, SV_MYSQL_DATABASE);
I noted down that I am not able to connect over mysql server all the time.
if trying 100 times failing 3 time.
and getting following error
echo($mdbconnection->connect_errno);
printing:
2003
and if I am trying second time after failing it{echo($mdbconnection->connect_errno);} will give always 1045.
I am trying to solve this bug.
Any ideas would be appreciated.
The 2003 error code means the connection couldn't be established:
https://dev.mysql.com/doc/refman/5.5/en/error-messages-client.html
Error code 1045 means the client connected but the server rejected the credentials (access denied):
https://dev.mysql.com/doc/refman/5.5/en/error-messages-server.html
I'd say that if you're getting the 2003 error code a few times out of every 100 tries, it sounds like some of the possibilities could be:
Some intermediate application or piece of hardware might be seeing your attempts as a possible flood attack (DDoS) and could be intercepting and blocking the connection (if you're connecting 100 times really quickly)
You might have some network stability issues on the client side. It might be worth the time to run Wireshark and reproduce the problem with it running in order to capture the problem and see if it shows anything significant (e.g. DNS failure).
The MySQL server might be crashing and then restarting. Check your server-side MySQL error log (https://dev.mysql.com/doc/refman/5.7/en/error-log.html). Actually, you should really do this as a first step any time you have bizarre behavior in MySQL.
If the MySQL server log doesn't show anything, check your system logs, especially if you're logging anything like blocked firewall (iptables or whatever f/w you're using) packets and search them for your client IP around the time of the problem.
Finally, if you can reproduce this easily/quickly (e.g. make 100 connections via a script and see it fail), try eliminating SSL out of the equation and connecting without SSL and see if it gives you the same problem. If it works flawlessly without SSL, perhaps there's a problem with the SSL library that was used during the compilation of your MySQL package.
You might also want to check to see if you have any load-balancing in place that might make your script connect to different instances of the MySQL server (this is less likely, but could explain the symptoms you're seeing if one server is down and the next doesn't have the credentials you're providing)

Can connect to database on server but cannot insert. Works on mamp localhost

I created a website which was fully functional on my computer's MAMP. When I placed it on the server, everything works well except for the fact that I cannot insert a new user into the DB. I'm partially concerned that the SSL cert is interrupting it, but I don't know enough about this to determine that. To troubleshoot this I did the following:
1. confirmed the connection works by returning row numbers and data that I manually placed into the database
2. confirmed openSSL is active/on
3. confirmed proper placement of my ssl certs through a separate site that confirms their presence
4. checked the error log on the server (which showed no errors) and then created a script to cause an error as proof of principle it works
5.confirmed the phpmyadmin user has full privledges
6. I have two user types and scripts that both don't work that worked on MAMP so I'm fairly confident its not poor coding
Further, all my php sql statements have built in mysqli_error($conn) which show no errors, and when I attempted a basic
"INSERT INTO users (name) VALUES ('john')"
scenario, it was unsuccessful.
My feeling that it is the ssl stems from the fact that my other (non-encrypted) sites don't have this problem. Is there something basic I'm missing?
Its not the SSL, its your configuration. See into it. If you can insert while doing it in the phpmyadmin with a raw sql, then check your config like the hostname user and db name. What server you are using?

Database connection error (2): Could not connect to MySQL

I am getting this error on my Joomla site.
Please note:
I have checked configuration file and there is no error in it.
I get this error few times a day. Without making any change it gets connected and some time this error appears.
Can someone please help in this.
Thanks
Dani
This happens when the MySQL server is overloaded, and so it stops responding. If you are on a shared hosting, then you should ask to be moved to a less crowded server. If you are on a VPS (with a fair use policy) or on a dedicated server, then you should enable and check the slow query log for the slow queries causing your MySQL server to crash.

Check whether PHP incompatibility or MySqli incompatibility the issue?

I created a site, built it and tested it on my own server. Now uploading to the client's server and every page with PHP/MySqli doesn't work. When the php/MySqli script appears in the page it just ends there, cutting out the rest of the content, footer etc.
Here is the version of the site on my server that works
http://progressivewebsolutions.ca/expmed/researchers.php
and here is the one on the clients server that doesnt work...
http://expmed.mcgill.ca/researchers.php
the client server is running php 5.2.6
mysql 5.0.45
On the dbconnect file it is supposed to throw an error if it cannot connect and does not throw the error. Regardless of login info and password.
My question is what tools exist to check this issue and solve it? I taught myself to code and am constantly learning, just need a bit of guidance.
Thank You,
I would look first in the web server's error log. Many PHP errors that are not output to the HTML are sent to the error log.
Make sure you have PHP error reporting enabled. See also How to get useful error messages in PHP?
If you want more help, I suggest you edit your question above and show the code you use to connect to the MySQL instance.
Another strategy is to log into a shell on the PHP appserver host and try using the mysql command-line client to connect to the MySQL instance, using the same host, user, password that your PHP script uses.
$ mysql -h mysqlhost -u username -p
Enter password: <enter password here>
That will test if the hosts can talk to each other, and whether the login works (keep in mind MySQL connection privileges may be restricted by host, so one login that works from one appserver may not work from other appservers).
Start to perform a phpMyInfo in order to see if Mysqli is "on".
On the other way, under PHP, in such a case, the basic way of putting some "echo" along the code is, maybe, the best way.
After a look at the phpinfo(),it seems error reporting is off. So even if you have some errors, you cant' see them.
Just add:
error_reporting(E_ALL);
ini_set('display_errors','On');
at the beginning of your page and maybe you'll see the errors.
Good luck!
Peter

Bad php codes can cause this(Error:Connection timed out) type of errors in FTP?

Sometimes when i am trying to connect to my server through filezilla i am getting this error at the same time my site and phpmyadmin is also down and getting errors like this mysql error: MySQL server has gone away or some times too many connections. It was working fine for last two days. 2 days before i altered tables in my database added some code in my .inc files (ie, php code) after that only i am having this problem. But some times i can connect to server and both my site and phpadmin is also loaded. I would like to know whether bad php codes can cause this(Error:Connection timed out) type of errors in FTP? Please help me..
SOLVED
Problem was with the server and they have corrected it. Thanks a lot
to all of you who responded to my question
Seems like your code is establishing too many MySQL connections, can you add the code to your question to confirm? (Do you have a DB connection in a loop by any chance?)
Regarding post-rollback errors, as you have not stated what you have tried, here is a slew of possible solutions.
MySQL #2002 forum post - A few possible solutions here.
linuxquestions forum post - (setting 'socket = /var/lib/mysql/mysql.sock' in my.cf)
'Solve: Can’t connect to local MySQL server through socket /tmp/mysql.sock'
The basic problem is most likely that you do not have the socket set correctly, check where the .sock is and what is currently set to in your settings.
Aside: You could go for a clean install of LAMP / XAMPP / whatever, may end up being quicker if possible assuming you can't fix the issue itself.

Categories