久久久久久久视色,久久电影免费精品,中文亚洲欧美乱码在线观看,在线免费播放AV片

<center id="vfaef"><input id="vfaef"><table id="vfaef"></table></input></center>

    <p id="vfaef"><kbd id="vfaef"></kbd></p>

    
    
    <pre id="vfaef"><u id="vfaef"></u></pre>

      <thead id="vfaef"><input id="vfaef"></input></thead>

    1. 站長資訊網(wǎng)
      最全最豐富的資訊網(wǎng)站

      PHP如何使用mysqli_real_escape_string()函數(shù)?

      本篇文章給大家介紹一下PHP使用mysqli_real_escape_string()函數(shù)的方法。有一定的參考價值,有需要的朋友可以參考一下,希望對大家有所幫助。

      PHP如何使用mysqli_real_escape_string()函數(shù)?

      PHP如何使用mysqli_real_escape_string()函數(shù)?用法示例

      mysqli_real_escape_string()函數(shù)是PHP中的內(nèi)置函數(shù), 用于轉義所有特殊字符以用于SQL查詢。在將字符串插入數(shù)據(jù)庫之前使用它, 因為它刪除了可能干擾查詢操作的任何特殊字符。

      當使用簡單的字符串時, 它們中可能包含特殊字符, 例如反斜杠和撇號(尤其是當它們直接從輸入了此類數(shù)據(jù)的表單中獲取數(shù)據(jù)時)。這些被認為是查詢字符串的一部分, 并且會干擾其正常運行。

      <?php    $connection = mysqli_connect(      "localhost" , "root" , "" , "Persons" );            // Check connection  if (mysqli_connect_errno()) {       echo "Database connection failed." ;  }      $firstname = "Robert'O" ; $lastname = "O'Connell" ;     $sql ="INSERT INTO Persons (FirstName, LastName)               VALUES ( '$firstname' , '$lastname' )";         if (mysqli_query( $connection , $sql )) {             // Print the number of rows inserted in      // the table, if insertion is successful      printf( "%d row inserted.n" , $mysqli ->affected_rows); } else {             // Query fails because the apostrophe in       // the string interferes with the query      printf( "An error occurred!" ); }     ?>

      在上面的代碼中, 查詢失敗, 因為使用mysqli_query()執(zhí)行撇號時, 會將撇號視為查詢的一部分。解決方案是在查詢中使用字符串之前使用mysqli_real_escape_string()。

      <?php     $connection = mysqli_connect(          "localhost" , "root" , "" , "Persons" );     // Check connection  if (mysqli_connect_errno()) {       echo "Database connection failed." ;  }          $firstname = "Robert'O" ; $lastname = "O'Connell" ;     // Remove the special characters from the // string using mysqli_real_escape_string     $lastname_escape = mysqli_real_escape_string(                      $connection , $lastname );                        $firstname_escape = mysqli_real_escape_string(                      $connection , $firstname );     $sql ="INSERT INTO Persons (FirstName, LastName)              VALUES ( '$firstname' , '$lastname' )";    if (mysqli_query( $connection , $sql )) {             // Print the number of rows inserted in      // the table, if insertion is successful      printf( "%d row inserted.n" , $mysqli ->affected_rows); }     ?>

      輸出如下:

      1 row inserted.

      贊(0)
      分享到: 更多 (0)
      網(wǎng)站地圖   滬ICP備18035694號-2    滬公網(wǎng)安備31011702889846號