PHP – PHP Error[2]: Error while sending QUERY packet. PID=*

In the company project today, such an error occurred when yiIC was used to run the database write operation, as shown in the figure below:

Project Scenario:
A big insert SQL and format for the insert INTO the TABLE VALUES (‘ A ‘, ‘B’, ‘C’), (‘ A ‘, ‘B’, ‘C’), (‘ A ‘, ‘B’, ‘C’)…
Code snippet:

It turns out that MySQL’s max_allowed_packet is too small.

The default max_allowed_packet is only 16M, which will occur if the SQL exceeds the set size.
Solutions:
1) Modify the MySQL configuration file
Edit my.cnf (My.ini under Windows) in the [mySQld] section or the server configuration section of mysql
Max_allowed_packet = 50M (or max_allowed_packet = 50*1024*1024)
2) Command line modification
set global max_allowed_packet = 50*1024*1024

Read More: