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
Can you paste the query that caused the error?
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
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.
Sadly i don't have access to my web hosting server, so i cannot change the MYSQL configuration.
Thanks a lot @karsen and @mudmin.
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