Hi, I'm currently using a second "wpdb" object to connect to a MariaDB database. Google gemini says this is not recommended because:
Singleton Pattern: The wpdb object is designed to be a singleton, meaning there's only one instance of it per request. Creating a second instance can disrupt this pattern and lead to unexpected results.
Resource Management: WordPress's built-in resource management system is optimized for a single wpdb instance. Creating a second instance can complicate resource management and potentially lead to issues like connection timeouts or memory leaks.
Compatibility: WordPress's core functionality and many plugins and themes rely on the wpdb object. Introducing a second instance can interfere with these dependencies and cause compatibility problems.
I don't know what a singleton is so is what Gemini said true? I've seen many examples where they recommend a second wpdb object (in a second variable).
If it is OK, do I need to close this second connection myself? If so what is the best way? I'm assuming the open is an expensive operation.
If I need to use "mysqli_connect", same question about opening/closing.
I'm looking at my use of "wpdb" because of these PHP error messages (and 500 & 503 server responses):
[14-Oct-2024 02:56:44 UTC] PHP Warning: mysqli_real_connect(): (HY000/1203): User xxxusernamexxx already has more than 'max_user_connections' active connections in /home/yyyy/public_html/wp-includes/class-wpdb.php on line 1982
[14-Oct-2024 03:30:30 UTC] PHP Warning: mysqli_real_connect(): (HY000/2006): MySQL server has gone away in /home/yyyy/public_html/wp-includes/class-wpdb.php on line 198
Now the website is low on resources and as a NFP organisation (which I volunteer at), getting it better resourced is problematic. So the above could be due to lack of RAM. But when it goes bad it is bad for a long time. I suspect the timing of web crawlers is the main cause if load is the issue and I have have to turn them all off in "robots.txt"...
Thanks for any help :-)