Forums / General Questions / PHP Warning: mysqli_connect() - Operation not permitted

PHP Warning: mysqli_connect() - Operation not permitted

Views: 105

Results 1 to 3 of 3
22 Sep 2026, 8:00 AM [edited]
#1
yesaul avatar

yesaul

New Zenner

Join Date:
Apr 2011
Location:
Espoo, Finland
Posts:
73
Plugin Contributions:
0

PHP Warning: mysqli_connect() - Operation not permitted

Good day,

I have been using Hostinger's shared hosting (www.hostinger.com) for my Zen Cart store for a long time

(no setup changes, nor hosting plan changes recently)

A while ago, I started receiving the following error message:

PHP Warning: mysqli_connect(): (HY000/2002): Operation not permitted in /includes/classes/db/mysql/query_factory.php

which occurs at the following line in query_factory.php:

$this->link = mysqli_connect($db_host, $db_user, $db_password, $db_name, (defined('DB_PORT') ? DB_PORT : null), (defined('DB_SOCKET') ? DB_SOCKET : null));

Before contacting the hosting provider's support or asking stupid questions here, I checked Hostinger's knowledge base and found the following information:

If your website is showing a database connection error such as:

  • PHP Fatal error: Uncaught mysqli_sql_exception: Operation not permitted

  • Connection failed: Operation not permitted

  • ERROR: Could not connect. Operation not permitted

  • SQLSTATE[HY000] [2002] Operation not permitted

This means your website is likely opening a new MySQL connection on every page request, instead of reusing an existing one. Hostinger enforces a per-account MySQL connection rate limit (20 new connections per second) to ensure fair resource usage across all customers. Websites that open a fresh connection on every request can exceed this limit during traffic bursts, causing the error above.

To resolve the issue, you just need to switch to persistent MySQL connections.

Find the line that looks like this:

mysqli_connect("localhost", $user, $pass, $db);

Change "localhost" to "p:localhost":

mysqli_connect("p:localhost", $user, $pass, $db);

The "p:" prefix tells PHP to use a persistent connection, keeping it open across requests instead of creating a new one each time.

As I am definitely not an expert in databases, could some of the gurus here possibly share their opinion on whether this could really be a solution? (a reliable and safe solution, I mean - I am afraid to check this on my running database, but I cannot simulate this error in a test environment)

Thank you in advance

Zen Cart 2.2.2 PHP Version: 8.3.33 Database Engine: MySQL 11.8.9-MariaDB-log

22 Sep 2026, 12:43 PM
#2
dbltoe avatar

dbltoe

Totally Zenned

Join Date:
Jan 2004
Location:
N of San Antonio TX
Posts:
9,864
Plugin Contributions:
18

Re: PHP Warning: mysqli_connect() - Operation not permitted

Yes, Hostinger's advice is sound, and it's safe for Zen Cart. But don't edit query_factory.php to do it. Zen Cart passes DB_SERVER from your configure.php straight into mysqli_connect(), so you get the same result by changing the constant.

In BOTH files:

includes/configure.php

YOUR_ADMIN/includes/configure.php

change

define('DB_SERVER', 'localhost');

to

define('DB_SERVER', 'p:localhost');

That's the whole change. It survives upgrades because configure.php is never overwritten, and it's instantly reversible: take the "p:" back off and you're exactly where you started.

You'll notice configure.php already has define('USE_PCONNECT', 'false'). Ignore it. That setting dates from the old mysql extension; the mysqli version of query_factory stores the value and never acts on it (1.5.8 and later even mark the parameter "unused" in the code). Setting it to 'true' does nothing.

Why it's safe:

- PHP's mysqli reuses the persistent link only within the same PHP worker process, and it resets the session state (mysqli_change_user) before handing it to the next request, so nothing leaks between visitors. Zen Cart re-sends its charset and time_zone settings on every connect() anyway.

- Zen Cart doesn't use temporary tables or long-running transactions on that connection, which are the classic things that misbehave with persistent links.

- It only helps on a server where PHP processes persist between requests (LiteSpeed lsphp or PHP-FPM). Hostinger runs LiteSpeed, which is why they recommend it. If your host ran PHP as plain CGI, the prefix would be silently ignored.

Two small caveats:

- If a backup plugin or a custom script shells out to mysqldump using DB_SERVER, it'll choke on "p:localhost". Core Zen Cart doesn't do that; check before you rely on it.

- "Operation not permitted" is Hostinger's rate limit (20 new connections per second per account), not a Zen Cart bug. Persistent connections cut the number of new connections, but if the bursts are coming from bots hammering your site, you'll also want to look at what's generating that traffic.

And you don't need a test environment. Make the change, load a few storefront and admin pages, and check /logs for new myDEBUG files. If anything looks off, remove the two characters.

Need a hand with Zen Cart? Hire the team at myZenCartZone.com for upgrades, repairs, and custom plugins.
Zen Cart Certified hosting at myZenCartHost.com

22 Sep 2026, 8:41 PM
#3
yesaul avatar

yesaul

New Zenner

Join Date:
Apr 2011
Location:
Espoo, Finland
Posts:
73
Plugin Contributions:
0

Re: PHP Warning: mysqli_connect() - Operation not permitted

@dbltoe

Thank you very much for the time you devoted to my question and for the detailed answer.

I hope your comprehensive explanations will be useful not only to me but also to other community participants.