Проблема в том, что я называю свои элементы формы следующим образом (выделено):
There are the collection of arrays in my form. Now I want to save these arrays in MySql database table which has json dataType (I am using MySQL v-8 with PHPDO). For this purpose I have used the following function to convert my $_POST array to json array:
$case = json_encode($_POST['case']);
It working fine and saving record in my table's columns but here is the problem that it stores the keys with the following manners:
введите описание изображения здесь
На приведенном выше снимке вы можете увидеть, что каждый ключ заключен в двойные кавычки , а затем одинарные кавычки .
Мне нужно сохранить ту же запись со столбцом json, но без одинарных кавычек после двойных кавычек .
Что я делаю не так? Мой код Php для приведенного выше преобразования из массива $ _POST ['case'] в массив json выглядит следующим образом:
......
$case = json_encode($_POST['case']);
$ret = json_encode($_POST['ret']);
$discussion = $_POST['discussion'];
$next_appointment_date = $_POST['next_appointment_date'];
$remarks = isset($_POST['remarks']) && !empty($_POST['remarks']) ? trim($_POST['remarks']):'';
$signature = isset($_POST['signature']) && !empty($_POST['signature']) ? trim($_POST['signature']):'';
//search the same case details before saving...
$sql_search = "SELECT * FROM case_information
WHERE case_info->>'$.first_party' = :first_party
AND case_info->>'$.second_party' = :second_party
AND case_info->>'$.case_nature' = :case_nature
AND case_info->>'$.received_date' = :received_date";
$parem_search = array(':first_party'=>$_POST['case']["'first_party'"],
':second_party'=>$_POST['case']["'second_party'"],
':case_nature'=>$_POST['case']["'case_nature'"],
':received_date'=>$_POST['case']["'received_date'"]);
if($db->dbQuery($sql_search,$parem_search)){
echo('3');
}else{
//insert new record
$sql_insert = "INSERT INTO case_information (
case_info,
instituted_by,
returned_to,
discussion,
remarks,
next_date_apt,
person_signature,
entry_made_on
)
VALUES
(
:case_info,
:instituted_by,
:returned_to,
:discussion,
:remarks,
:next_date_apt,
:person_signature,
:entry_made_on
)";
$param = array(
':case_info'=>$case,
':instituted_by'=>$ins,
':returned_to'=>$ret,
':discussion'=>$discussion,
':remarks'=>$remarks,
':next_date_apt'=>$next_appointment_date,
':person_signature'=>$signature,
':entry_made_on'=>date('Y-m-d')
);
//echo($sql_insert);
if($db->dbQuery($sql_insert,$param)){
echo('4');
}else{
.
.