汇文从marc_idx根据书名检索图书

<?php
ini_set ( "display_errors" , true ) ;

$dbpara['oracle']['username'] = 'libsys';
$dbpara['oracle']['password'] = 'mypassword';
$dbpara['oracle']['url'] = '210.28.99.99:1521/libsys';
$dbpara['oracle']['usepdo'] = false;

class OraDBConnection
{

    private $connection = null;

    public function __construct()
    {
        global $dbpara;
        $this->connection = oci_connect($dbpara['oracle']['username'], $dbpara['oracle']['password'], $dbpara['oracle']['url'], 'al32utf8');
        if (!$this->connection)
        {
            header('HTTP/ 500');
            $e = oci_error();;
            die('failed to connect to database: ' . $e['message']);
        }
    }

    public function __destruct()
    {
        if ($this->connection)
        {
            oci_close($this->connection);
        }
    }

    public function prepare($sqlString)
    {
        return new OraStatement($this->connection, $sqlString);
    }
}

class OraStatement
{
    private $statement = null;

    public function __construct($connection, $sqlString)
    {
        $this->statement = oci_parse($connection, $sqlString);
    }

    public function __destruct()
    {
        if ($this->statement)
        {
           oci_free_statement($this->statement);
       }
    }

    public function execute()
    {
        $result = oci_execute($this->statement);
    }

    public function bindParam($param, $value)
    {
        oci_bind_by_name($this->statement, $param, $value);
    }

    public function fetchObject()
    {
        $result = oci_fetch_array($this->statement);
        if ($result == false)
        {
            return false;
        }
        $resultObj = null;
        foreach ($result as $key => $value)
        {
            $property = strtolower($key);
            $resultObj->$property = $value;
        }
        return $resultObj;
    }

        /** return 0 or 1, it will not return the row num */
    public function rowCount()
    {
        /* before oci_num_rows, we must call oci_fetch_object */
        $this->fetchObject();
        return oci_num_rows($this->statement);
    }
}

function search_books($title)
{
                $connection =new OraDBConnection(); 
  
        $sql = '
            SELECT DISTINCT marc.MARC_REC_NO, doc_type_code.DOC_TYPE_NAME, 
              dump(marc.M_TITLE, 16) as M_TITLE,
              dump(marc.M_AUTHOR, 16) as M_AUTHOR,
              dump(marc.M_PUBLISHER, 16) as M_PUBLISHER,
              dump(marc.M_PUB_YEAR, 16) as M_PUB_YEAR,
              marc.CATA_DATE,
              dump(marc.M_CALL_NO,16) as M_CALL_NO
              from  marc_idx idx0,marc, doc_type_code,call_no_lst,indi_acct,
            where 
            marc_rec_no = marc.marc_rec_no AND 
            marc.marc_rec_no = call_no_lst.marc_rec_no AND

            marc.marc_rec_no = indi_acct.marc_rec_no AND

            marc.M_TITLE like "%linux%"
            
            ';


            $sql = "select marc_rec_no,m_title,M_AUTHOR,
            m_publisher,m_pub_year,cata_date,m_call_no 
            from 
            (select marc.marc_rec_no,marc.m_title,marc.M_AUTHOR,
            marc.m_publisher,marc.m_pub_year,marc.cata_date,marc.m_call_no
             from marc_idx  ,marc
             where marc_data_code = '200a' 
             and marc_idx.marc_rec_no = marc.marc_rec_no 
             and instr(marc_idx.marc_idx_cont, :title)>0
              order by marc.cata_date desc
            )where  rownum <=20
            ";
            $statement = $connection->prepare($sql);
            $statement->bindParam(':title', $title);
            $statement->execute();
        $i=0;
        $book=array();
        while (($row = $statement->fetchObject() )) {
                $book[$i]= clone $row;
                $i++;
                //echo $i.":".$row->marc_rec_no.":".$row->cata_date.":".$row->m_call_no.":"
                //.$row->m_pub_year.":".$row->m_title.":".$row->author."<br /> \n";
        }

        return $book;

        unset($connection);
}

header("Content-type: text/html; charset=utf-8"); 

    if ( isset( $_REQUEST['title'] ) ){
        $book_title = $_REQUEST['title'];
        if ( isset( $_REQUEST['url'] ) ){
            $book_title = urldecode($book_title);
        }
        
        echo $book_title;
        $books=search_books($book_title);
        //var_dump($books);
        echo json_encode($books);
    }
?>



转载于:https://my.oschina.net/jianhui1980/blog/191104

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值