drsxzut183207938 2019-01-15 23:25
浏览 49

MySQL查询停止在实时服务器上工作(在localhost上工作)

I've been working on a blog website on localhost. I'm finally ready to move it over to a live server, but many of my queries stopped working! Below is one example of a query that worked, but no longer is working properly. Is there something I'm missing? Thanks in advance :)

public function search($query, $start, $limit)
{
    $stmt = $this->pdo->prepare("SELECT * FROM `articles` WHERE `status` = 1 AND LOWER(`title`) LIKE LOWER(:query) ORDER BY `id` DESC LIMIT :start, :limit");
    $stmt->bindParam(":query", $query, PDO::PARAM_STR);
    $stmt->bindParam(":start", $start, PDO::PARAM_INT);
    $stmt->bindParam(":limit", $limit, PDO::PARAM_INT);
    $stmt->execute();
    $articles = $stmt->fetchAll(PDO::FETCH_OBJ);
    $count = $stmt->rowCount();

    if($count > 0)
    {
        foreach($articles as $article)
        {
            $date = date('F jS, Y', strtotime($article->published));
            echo '<div class="article">
            <h2>'.$article->title.'</h2>
            <h4>'.$article->subtitle.', <span>'.$date.'</span></h4>
            <div class="imageWrapper">
                <img src="'.BASE_URL.$article->banner.'">
                <div class="articleHover">
                    <p>'.$this->shorten(strip_tags($article->content), 300).'...</p>
                </div>              
            </div>
            <div id="mobileDescription"><p>'.$this->shorten(strip_tags($article->content), 300).'...</p></div>
            <a href="article/'.$article->link.'">Read Article</a>
        </div>';
        }
    }
    else
    {
        echo "No Search Results...";
    }

}

No errors are thrown, just seems to return a count of 0 rows (Tested by echoing $count). There is data in the table and everything is set up correctly. If you view the page at https://nerbgamez.ca/blog you can see the articles displaying properly on the home page. It seems to only be an issue with the search. Below I'll show the ajax function used to call this query, maybe this will help.

Ajax function

index = 0;
app = 2;

...

$.ajax({
        url: 'https://nerbgamez.ca/blog/inc/ajaxFunctions.php',
        type: 'POST',
        data: {start:index, limit:app, index:3, query:$('#query').val()},
        success: function (res) {
            $('#searchResults').html(res);                  
        }
    });

ajaxFunctions.php

if($index == 3)
{
    $start = $_POST['start'];
    $limit = $_POST['limit'];
    $query = '%'.$_POST['query'].'%';

    $getFromA->search($query, $start, $limit);
}
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
    • ¥15 手机接入宽带网线,如何释放宽带全部速度
    • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
    • ¥15 ETLCloud 处理json多层级问题
    • ¥15 matlab中使用gurobi时报错
    • ¥15 这个主板怎么能扩出一两个sata口
    • ¥15 不是,这到底错哪儿了😭
    • ¥15 2020长安杯与连接网探
    • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么