将mysql查询转换为oracle查询

时间:2019-03-07 12:30:11

标签: php mysql oracle11g

我将数据库更改为oracle,我想知道应该更改哪个代码。 当我自己尝试时,它没有用。它给了我

  

警告:mysql_real_escape_string()期望参数1为字符串,第40行的D:\ xampp \ htdocs \ advance_search.php中提供的资源

     

致命错误:在以下位置调用未定义的函数oci_query()   D:\ xampp \ htdocs \ advance_search.php,第44行

错误..

     <?php  
 $connect = mysqli_connect("localhost", "root", "", "test_db");  
 if(isset($_POST["submit"]))  
 {  
      if(!empty($_POST["search"]))  
      {  
           $query = str_replace(" ", "+", $_POST["search"]);  
           header("location:advance_search.php?search=" . $query);  
      }  
 }  
 ?>  
 <!DOCTYPE html>  
 <html>  
      <head>  
           <title>Webslesson Tutorial | Search multiple words at a time in Mysql php</title>  
           <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />  
           <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>  
           <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>  
      </head>  
      <body>  
           <br /><br />  
           <div class="container" style="width:500px;">  
                <h3 align="center">Search multiple words at a time in Mysql php</h3><br />  
                <form method="post">  
                     <label>Enter Search Text</label>  
                     <input type="text" name="search" class="form-control" value="<?php if(isset($_GET["search"])) echo $_GET["search"]; ?>" />  
                     <br />  
                     <input type="submit" name="submit" class="btn btn-info" value="Search" />  
                </form>  
                <br /><br />  
                <div class="table-responsive">  
                     <table class="table table-bordered">  
                     <?php  
                     if(isset($_GET["search"]))  
                     {  
                          $condition = '';  
                          $query = explode(" ", $_GET["search"]);  
                          foreach($query as $text)  
                          {  
                               $condition .= "video_title LIKE '%".mysqli_real_escape_string($connect, $text)."%' OR ";  
                          }  
                          $condition = substr($condition, 0, -4);  
                          $sql_query = "SELECT * FROM tbl_video WHERE " . $condition;  
                          $result = mysqli_query($connect, $sql_query);  
                          if(mysqli_num_rows($result) > 0)  
                          {  
                               while($row = mysqli_fetch_array($result))  
                               {  
                                    echo '<tr><td>'.$row["video_title"].'</td></tr>';  
                               }  
                          }  
                          else  
                          {  
                               echo '<label>Data not Found</label>';  
                          }  
                     }  
                     ?>  
                     </table>  
                </div>  
          </div>  
      </body>  
 </html>  

警告:mysqli_real_escape_string()期望参数1为mysqli,第40行的D:\ xampp \ htdocs \ advance_search.php中给出的资源

警告:mysqli_query()期望参数1为mysqli,第44行的D:\ xampp \ htdocs \ advance_search.php中给出的资源

警告:mysqli_num_rows()期望参数1为mysqli_result,在第45行的D:\ xampp \ htdocs \ advance_search.php中给出空值 找不到数据

这些错误是什么意思?

1 个答案:

答案 0 :(得分:0)

我有同样的错误,我改用这种方法进行连接

<?php   
$db = "(DESCRIPTION = 
    (ADDRESS = 
        (PROTOCOL = TCP)
        (HOST = [host])
        (PORT = [port])) 
    (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = [service_name])))";
    $conn = oci_connect([schema_name], [schema_password], $db);
    if (!$conn) {
    $m = oci_error();
    echo $m['message'], "\n";
   exit;
}
else 
    echo 'connected';?>