首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >致命错误:未捕获错误:第27行对C:\cont_search.php中的boolean调用成员函数execute()

致命错误:未捕获错误:第27行对C:\cont_search.php中的boolean调用成员函数execute()
EN

Stack Overflow用户
提问于 2018-06-28 04:34:13
回答 1查看 647关注 0票数 -2

如何从两个表中检索和查询执行绑定形成json数组传递

cont_search.php

代码语言:javascript
复制
        <?php

    include "connection.php";
    $keyword=$_GET["context"];
    //Checking if any error occured while connecting
    if (mysqli_connect_errno()) {
        echo "Failed to connect to MySQL: " . mysqli_connect_error();
        die();
    }

    $query =$conn->prepare("(SELECT isbn, title, authors, accession, publisher, pubyear, pages, keywords, subheadings, booknote, rak, hr, vr,            status, 'book' as type FROM books WHERE title LIKE '%".$keyword."%' OR authors LIKE '%".$keyword."%' OR publisher LIKE                      '%".$keyword."%' OR pubyear LIKE '%".$keyword."%' OR keywords LIKE '%".$keyword."%' OR subheadings LIKE '%".$keyword."%' OR               booknote LIKE '%".$keyword."%')  
           UNION ALL
           (SELECT t_acc, t_title, t_author, t_university, t_puby, t_keywords, t_rak, t_hr, t_vr, t_status, 'thesis' as type FROM thesis WHERE t_title LIKE '%".$keyword."%' OR t_author LIKE '%".$keyword."%' OR t_university LIKE '%".$keyword."%' OR t_puby LIKE '%".$keyword."%' OR t_keywords LIKE '%".$keyword."%')");

 echo "Error: " . $query . "<br>" . $conn->error;

    $query->execute();

    $query->bind_result($isbn, $title, $authors, $accession, $publisher, 
  $pubyear, $pages, $key, $sub, $bkn, $rak, $hr, $vr, $status, $tacc, 
                        $ttile, $tauthor, $tuni, $tpuby, $tkey, $trak, $thr, 
   $tvr, $tstatus);


    $books = array(); 
    $data =array();
    //traversing through all the result 
        while($query->fetch()){
        $temp = array();
        $temp['isbn'] = $isbn; 
        $temp['title'] = $title; 
        $temp['authors'] = $authors; 
        $temp['accession'] = $accession; 
        $temp['publisher'] = $publisher; 
        $temp['pubyear'] = $pubyear; 
        $temp['pages'] = $pages; 
        $temp['keywords'] = $key; 
        $temp['subheadings'] = $sub; 
        $temp['booknote'] = $bkn; 
        $temp['rak'] = $rak; 
        $temp['hr'] = $hr; 
        $temp['vr'] = $vr;
        $temp['status'] = $status;
        $temp['t_acc'] = $tacc;
        $temp['t_title'] = $ttile;
        $temp['t_author'] = $tauthor;
        $temp['t_university'] = $tuni;
        $temp['t_puby'] = $tpuby;
        $temp['t_keywords'] = $tkey;
        $temp['t_rak'] = $trak;
        $temp['t_hr'] = $thr;
        $temp['t_vr'] = $tvr;
        $temp['t_status'] = $tstatus;


        array_push($data, $temp);

        }
        $books['ss'] = true; //ss=send status
        $books['search'] = $data;
    //displaying the result in json format 
        header('Access-Control-Allow-Origin: *');
        header('Content-type:application/json;charset=utf-8');
        echo json_encode($books);

    ?>

http://localhost/cont_search.php?context=english

I execute/run occur发生错误

错误:使用的SELECT语句具有不同的列数

致命错误:未捕获错误:在C:\cont_search.php中对boolean调用成员函数execute()

EN

回答 1

Stack Overflow用户

发布于 2018-06-28 04:43:28

您的第一个错误出现在sql查询中。

UNION内的每个SELECT语句必须具有相同的列数

第一个select中的列数多于第二个select中的列数

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51071000

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档