2017-12-18 5 views
0

私はmysqliに更新しようとしていますが、私はサイト全体をほぼ更新しましたが、私はGetSQLValueStringの問題に直面しています。 mysqliと互換性があるように、または必要に応じて削除/変更するには、これをどのように変更できますか?mysqliの代わりにGetSQLValueString

<?php 
if (!function_exists("GetSQLValueString")) { 
    function GetSQLValueString($theValue, $theType, $theDefinedValue = "", 
$theNotDefinedValue = "") 
    { 
     if (PHP_VERSION < 6) { 
      $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; 
     } 

     $theValue = function_exists("mysql_real_escape_string") ? 
      mysql_real_escape_string($theValue) : mysql_escape_string($theValue); 

     switch ($theType) { 
      case "text": 
       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; 
       break; 
      case "long": 
      case "int": 
       $theValue = ($theValue != "") ? intval($theValue) : "NULL"; 
       break; 
      case "double": 
       $theValue = ($theValue != "") ? doubleval($theValue) : "NULL"; 
       break; 
      case "date": 
       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; 
       break; 
      case "defined": 
       $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; 
       break; 
     } 
     return $theValue; 
    } 
} 

$colname_Recordset1 = "-1"; 
if (isset($_GET['stid'])) { 
    $colname_Recordset1 = $_GET['stid']; 
} 
mysqli_select_db($SIS,$database_SIS); 
$query_Recordset1 = sprintf("SELECT * FROM payments WHERE stid = %s", 
GetSQLValueString($colname_Recordset1, "int")); 
$Recordset1 = mysqli_query($SIS, $query_Recordset1) or die(mysqli_error()); 
$row_Recordset1 = mysqli_fetch_assoc($Recordset1); 
$totalRows_Recordset1 = mysqli_num_rows($Recordset1); 

?> 
+1

なぜパラメータ付きクエリでプリペアドステートメントを使用しないのですか? – FirstOne

+0

あなたの質問は、リファクタリングを依頼するには広すぎるだけでなく、何が問題であるかも不明です。 – FirstOne

+0

私は、パラメータ化されたクエリを持つ準備済みの文に慣れていないので、私に例を教えてもらえますか?ご協力ありがとうございました。 –

答えて

0

すべてmysql_にmysqli_を変更し、最初のパラメータとしてデータベースに接続を追加する必要があります。私の場合、データベースへの接続は$ conn_voteです。関数のパラメータとして$ conn_voteを追加したことに注意してください。

function GetSQLValueString($conn_vote, $theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
    { 
     $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; 

     $theValue = function_exists("mysqli_real_escape_string") ? mysqli_real_escape_string($conn_vote, $theValue) : 
mysqli_escape_string($conn_vote, $theValue); 

     switch ($theType) { 
     case "text": 
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; 
      break;  
     case "long": 
     case "int": 
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";  
      break;  
     case "double":  
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; 
      break; 
     case "date": 
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; 
      break; 
     case "defined": 
      $theValue = ($theValue != "") ? $theDefinedValue : 
$theNotDefinedValue; 
break; 
} 
return $theValue; 
} 
}