Datatables/PHP/MySQL: multiple tables on the same page not working
Datatables/PHP/MySQL: multiple tables on the same page not working
Link to test case:
Debugger code (debug.datatables.net): https://debug.datatables.net/efecis
Error messages shown: "MySQL server has gone away"
Description of problem: I have an old code written in PHP5 that I'm updating for PHP7+MySQL5.7. There is one page where several dynamic tables (15) are used and it used to work normally. Now, it gives me a connection error (MySQL server has gone away) for all tables except the first one. If I remove the initialization code for the first table, then the second one start to work but the others keep triggering the same error. If I test each Ajax call separately, it works fine, as it should, since the page was working before. Thus, the problem is that the server seems to be refusing more than one DataTable connection on the same page. I really think that this error might be something related to PHP and/or MySQL configuration, but I couldn't find a solution on the web. Does anyone have any idea of what's causing this and how to fix it?
This question has an accepted answers - jump to answer
Answers
The link for the debugger code seems to be broken, but that's the one generated by the debugger.
Maybe this SO Thread will help. You will probably need to do some debugging of MySql to determine why you are getting the error.
Kevin
Thanks for replying, Kevin. I tried what they suggest there, but it didn't work. I've explored the issue more and I've found out that for simpler queries, I'm able to open 4 or 5 tables on the same page, occasionally getting the same error. So, it seems something like the asynchronous calls are been too fast for MySQL/PHP server do handle connections properly? Is it possible a problem like this?
It's possible. Perhaps look at the max connections that the MySQL server is set up for? I'd also suggest checking it's error and debug logs.
Btw the debug trace says you are using DataTables 1.8.2 - that's a super old version now. It might be worth updating sometime.
Allan
Thanks, Allan. Just tried that, updating max_connections to 400 with no success. One thing I noticed: in my application previous versions, these Ajax calls each created a persistent connection using the now deprecated PHP function mysql_pconnect(). I updated all the code to PHP7 and started using mysqli_connect(). I wonder if this might be related also...
Guys, I'm closing this issue. I don't know why, but after turn on MySQL 'general_log' parameter and restart the mysql server the page suddenly started to work again... I have no idea of what was the problem and what solved it, given that there is no relation whatsoever between these things. But, as it seems, I believe this issue I brought here was an illusory one. Thank you all for your kind attention.
Thanks for the update. Good to hear you've got it sorted. If it comes back, keeping an eye on those logs would be my first suggestion.
Allan