MySQL到MySQLi的转换

时间:2016-12-21 18:53:14

标签: php mysqli

我刚开始使用PHP并需要MySQL中的简单代码的帮助,我想我需要在MySQLi中使用它因为我收到错误 我已将PHP代码更改为以下内容,现在出现以下错误:

 ! ) Notice: Use of undefined constant searchengine - assumed 'searchengine' in C:\wamp\www\search\results.php on line 6
Call Stack
#   Time    Memory  Function    Location
1   0.0004  242504  {main}( )   ...\results.php:0

索引页

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Helpy Search Engine</title>
</head>
<body>
    <h1>Go ahead, search.</h1>
    <form action="results.php" method="get">
        <input type="text" name="query" placeholder="Search..">
        <button type="submit">Search</button>
    </form>
</body>
</html>



<?php 

    $search = $_GET['query']; 

    ($GLOBALS["___mysqli_ston"] = mysqli_connect("localhost",  "root",  "")) or die(((is_object($GLOBALS["___mysqli_ston"])) ? mysqli_error($GLOBALS["___mysqli_ston"]) : (($___mysqli_res = mysqli_connect_error()) ? $___mysqli_res : false)));
    ((bool)mysqli_query($GLOBALS["___mysqli_ston"], "USE " . searchengine)); 

    $query = mysqli_query($GLOBALS["___mysqli_ston"], "SELECT * FROM results WHERE title LIKE '%".$search."%'"); 
    if(mysqli_num_rows($query) >= 1) { 
        while($a = mysqli_fetch_array($query)) { 
            echo "<a href='".$a['url']."'>".$a['title']."</a><p>".$a['description']."</p><hr/>"; 
        } 

    } else { 
        echo "Oh no! Nothing was found."; 
    } 


?>

1 个答案:

答案 0 :(得分:0)

好的,所以想通了。我把&#39; searchengine&#39;而不只是第6行的searchengine

排序。