<?php
namespace backend\controllers;
use backend\controllers;
use yii\helpers\Html;
$host = "localhost";	$userdb = "root";	$passdb = "";	$database = "ebook";
$con = mysql_connect("$host","$userdb","$passdb");

$id = isset($_REQUEST['id']) ? $_REQUEST['id'] : '';
if(! $con)
{
    $json_output1 = json_encode(array(
        'status' => 'error',
        'data' => '',
        'message' => 'Connect Error !',
    ));
    echo $json_output1;
}
else
{
    mysql_select_db("$database",$con);
    $strSQL='';
    if($id == 0)
    {
        $strSQL="SELECT id, title, author, publisher, image
                    FROM book
                    ";
    }
    else
    {
        $strSQL="SELECT id, title, author, publisher, image
                    FROM book
                    WHERE id = '$id'";
    }
    $result = mysql_query($strSQL);
    if(mysql_num_rows($result) > 0)
    {
        $json = array();

        while($row=mysql_fetch_assoc($result))
        {
            //$path= $_SERVER['SERVER_NAME'].'/ebook/backend/web/images/book/'.$row['image'];
            $path= Yii::$app->urlManager->baseUrl;
            $img= $path.'/images/book/'.$row['image'];
            //echo $img;exit;
            $json[]=array(
                'id'=>$row['id'],
                'title'=>$row['title'],
                'author'=>$row['author'],
                'publisher'=>$row['publisher'],
                'image'=>$img
            );

        }

        $json_output1 = json_encode(array(
            'status' => 'success',
            'data' => $json,
            'message' => '',
        ));
        echo $json_output1;
    }
    else
    {
        $json_output1 = json_encode(array(
            'status' => 'error',
            'data' => '',
            'message' => 'No match found !',
        ));
        echo $json_output1;
    }
}
?>