The following warnings occurred:
Warning [2] Undefined variable $unreadreports - Line: 26 - File: global.php(961) : eval()'d code PHP 8.2.25 (Linux)
File Line Function
/global.php(961) : eval()'d code 26 errorHandler->error
/global.php 961 eval
/showthread.php 28 require_once





× This forum is read only. As of July 23, 2019, the UserSpice forums have been closed. To receive support, please join our Discord by clicking here. Thank you!

  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Error while sending QUERY packet
#1
Hi all,
I got this error when parsing JSON then saving it into my database,

PHP Warning: Error while sending QUERY packet. PID=23158 in /home/myweb/public_html/users/classes/DB.php on line 56

Im using shared web hosting, so i cannot change the php.ini file.

Please help me to solve my problem
  Reply
#2
Can you paste the query that caused the error?
  Reply
#3
just for info sakes, you can include a file called php.ini in root folder on many shared servers, i believe either godaddy or 1&1 can remember which tho
  Reply
#4
Here the script:

<?php
$queryTracking_id = $db->query("SELECT tracking_id FROM tbaduan_lapor ORDER BY id DESC");
$TrackingIDs = $queryTracking_id->results(true);

// print_r($TrackingIDs);

// echo "LAST_INSERT_ID : ".$id_tracking;

$data_string = array("jumlah" => 100);

//Here are CURL function

$response = curl_exec($ch);
//echo $response;

//execute the session
//$curl_response = curl_exec($curl);
//finish off the session
curl_close($ch);
$curl_jason = json_decode($response, true);

// print_r($curl_jason);
$LAPORdata = $curl_jason['data']['ROWS'];
$count_rec = 1;
$count_LAPORdata = count($LAPORdata);

// echo "tracking_id= ".$LAPORdata[0]['tracking_id'];
//print_r($curl_jason);

$indexLAPOR = 0;
foreach($LAPORdata as $LAPORkey => $LAPORvalue) {
# code...
//if ($count_rec == 1) {
# code...

$tracking_idValue = $LAPORdata[$indexLAPOR]['tracking_id'];

$cSub = 1;

if (!in_array_r($tracking_idValue, $TrackingIDs)) {
# code...
echo $count_rec.". ++++++++++++++++++++++++++++++++++++++<br>";

foreach ($LAPORvalue as $columnkey => $columnvalue) {
# code...
// if tanggal_
if (!is_array($columnvalue)) {
echo " ".$cSub.". ".$columnkey." => ".htmlspecialchars($columnvalue)."<br>\n\n";
$firstfields[$columnkey] = $columnvalue;
if ($columnkey == "sumber_laporan") {
# code...
$firstfields[$columnkey] = strtoupper($columnvalue);
}
//07 July 2017 21:28:30
} // END (!is_array($columnvalue))
else {
//$klasifikasi = array();
// echo " ".$cSub.". ".$columnkey." => ".$columnvalue."<br>\n\n";

if ($columnkey === "klasifikasi") {
# code...
//print_r($columnvalue);
foreach ($columnvalue as $key => $value) {
# code...
$klasifikasifields['tracking_id'] = $tracking_idValue;
$klasifikasifields[$key] = $value;
}
$db->insert('tbaduan_klasifikasi', $klasifikasifields);
//print_r($klasifikasifields);
}
if ($columnkey === "area_laporan") {
# code...
//print_r($columnvalue);
foreach ($columnvalue as $key => $value) {
# code...
$area_laporanfields['tracking_id'] = $tracking_idValue;
$area_laporanfields[$key] = stripslashes($value);
}
$db->insert('tbaduan_area', $area_laporanfields);
//print_r($area_laporanfields);
}
if ($columnkey === "kategori") {
# code...
//print_r($columnvalue);
foreach ($columnvalue as $kategoriKey => $kategoriValue) {
# code...
foreach ($kategoriValue as $key => $value) {
# code...
$kategorifields['tracking_id'] = $tracking_idValue;
$kategorifields[$key] = stripslashes($value);
}
$db->insert('tbaduan_kategori', $kategorifields);
//print_r($kategorifields);
}
}
if ($columnkey === "disposisi") {
# code...
if (count($columnvalue) == 0) {
# code...
$firstfields['disposisi'] = 0;
}
else {
$firstfields['disposisi'] = 1;
}
//print_r($columnvalue);
foreach ($columnvalue as $key => $value) {
# code...
$disposisifields['tracking_id'] = $tracking_idValue;
$disposisifields[$key] = stripslashes($value);
}
$db->insert('tbaduan_disposisi', $disposisifields);
//print_r($disposisifields);
}

if ($columnkey === "instansi_terkait") {
# code...
//print_r($columnvalue);
foreach ($columnvalue as $instansiKey => $instansiValue) {
# code...
foreach ($instansiValue as $key => $value) {
# code...
$instansifields['tracking_id'] = $tracking_idValue;
$instansifields[$key] = stripslashes($value);
}
$db->insert('tbaduan_instansi', $instansifields);
//print_r($instansifields);
}
}

if ($columnkey === "tindaklanjut") {
# code...
//print_r($columnvalue);
foreach ($columnvalue as $tindaklanjutKey => $tindaklanjutValue) {
# code...
foreach ($tindaklanjutValue as $key => $value) {
# code...
$tindaklanjutfields['tracking_id'] = $tracking_idValue;
$tindaklanjutfields[$key] = stripslashes($value);
}
$db->insert('tbaduan_tindaklanjut', $tindaklanjutfields);
//print_r($tindaklanjutfields);
}
}

if ($columnkey === "tags") {
# code...
//print_r($columnvalue);
foreach ($columnvalue as $tagsKey => $tagsValue) {
# code...
foreach ($tagsValue as $key => $value) {
# code...
$tagsfields['tracking_id'] = $tracking_idValue;
$tagsfields[$key] = stripslashes($value);
}
$db->insert('tbaduan_tags', $tagsfields);
//print_r($tagsfields);
}
}
// echo "<br>\n\n";
}
$cSub++;
} // END foreach ($LAPORvalue as $columnkey => $columnvalue)

// echo "<br>";
$count_rec++;
$myFirstfield[] = $firstfields;
$db->insert('tbaduan_lapor',$firstfields);
} //END if ($id_tracking != $tracking_idValue)
//}//END if ($count_rec == 1)
$indexLAPOR++;
} // END foreach($LAPORdata as $LAPORkey => $LAPORvalue)

usort($myFirstfield, 'date_compare');

for ($i=0; $i < count($myFirstfield); $i++) {
# code...
foreach ($myFirstfield[$i] as $key => $value) {
# code...
$result[$key] = $value;
}
$db->insert('tbaduan_lapor',$result);
// /print_r($result);
}
?>

Thank you a lot.
  Reply
#5
Your error can be caused by several issues, usually relating to sending large amounts of data to your database. If the data is large, change your
Code:
max_allowed_packet
variable before running your query. It defaults to 16MB but your shared host may have lowered it, or you might just be sending more than that. This changes it to 32MB:
Code:
SET GLOBAL max_allowed_packet=33554432;

It might also be timing out before it can finish sending. Also try this to change the seconds before timeout:
Code:
SET GLOBAL wait_timeout 10;

Try these and let us know if you still have issues. This isn't a UserSpice specific issue so you might find a faster answer by searching on Google than waiting for us to help you.
  Reply
#6
Sadly i don't have access to my web hosting server, so i cannot change the MYSQL configuration.
Thanks a lot @karsen and @mudmin.
  Reply
#7
try creating a file called php.ini then add @karsens fix wrapped in php tags then upload to your root folder, some hosts it works for and others it doesnt
  Reply
#8
Those were MYSQL query commands that you can use as
Code:
$db->query('SET GLOBAL max_allowed_packet=33554432;', array());
, not php.ini changes. I tested it out and they do require the SUPER privilege, so you most likely wouldn't be able to use the commands anyway Sad

Since that's not an option, try splitting your insert field arrays into smaller arrays and run more insert queries.
  Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)