1
ここにいくつかのPHPコードがあります。私は自分のデータベースから行を取得しようとしているので、私はそれも私が作ったアプリで使うことができるようにJSON配列に変換します。私はDBOperations.phpからFunction.phpに配列を渡すのが難しいです。ここでPHPでこの関数に配列を返すには?
はDBOperations.phpのコードです:
//Read from diary table and enter results into an array
public function readDiaryOperation($email)
{
$query = $this-> conn -> prepare("SELECT title,entry FROM diary WHERE email = :email");
$query -> execute(array(':email' => $email));
if($query->rowCount() > 0)
{
$data = $query->fetchAll(PDO::FETCH_ASSOC);
return json_encode($data);
}
else
{
$json['success'] = 0;
$json['message'] = 'No Data found';
$json['myintro'] = '';
return json_encode($json);
}
}
そしてここでは、$メールが私のアプリからの換装を使用して設定されている私のfunctions.php
//Login user after checking that the user exists within the database or the fields are empty
public function readDiary($email)
{
$db = $this -> db;
if (!empty($email))
{
if ($db -> readDiaryOperation($email))
{
$result = $db -> readDiaryOperation($email);
if(!$result)
{
$response["result"] = "failure";
$response["message"] = "Read Diary Failure - Error Code 1";
return json_encode($response);
}
else
{
$response["result"] = "success";
$response["message"] = "Read Diary Operation Successful";
$response["diary"] = $result;
return json_encode($response);
}
}
else
{
$response["result"] = "failure";
$response["message"] = "Read Diary Failure - Error Code 2";
return json_encode($response);
}
}
else
{
return $this -> getMsgParamNotEmpty();
}
}
ためのコードです。