私は、MySQLでOSCommerceを使用するプロジェクトに取り組んでいます。私はtep_db_input()またはtep_db_prepare_input()を使用するべきかについて混乱しています。私は挿入/更新されている任意の文字列の周りにtep_db_input()を使用する必要があると思いますが、他の関数を使用する必要がありますか? Iは、した場合OSCommerce tep_db_input対tep_db_prepare_input
例えば、データベースからいくつかのデータを選択し、その結果を使用するために、次にINSERTは別のテーブルに行、私はいくつかの点で入力を準備する必要がありますか?あるいは、もう一度tep_db_inputを使うだけですか?
$width = '3"'; // 3 inches
$new_height = '3\' 5"'; // 3 feet 5 inches
$result = tep_db_query(
"SELECT height
FROM measurements
WHERE width = '".tep_db_input($width)."'"
);
while ($row = tep_db_fetch_array($result)) {
tep_db_query(
"INSERT INTO measurement_history (
field,
old_value,
new_value
) VALUES (
'height',
'".tep_db_input($row['height'])."',
'".tep_db_input($new_height)."'
)"
);
}
これは間違いありませんか?
編集::場合、誰もがそれらの機能に精通していない、ここではそれらの定義は以下のとおりです。
function tep_sanitize_string($string) {
$patterns = array ('/ +/','/[<>]/');
$replace = array (' ', '_');
return preg_replace($patterns, $replace, trim($string));
}
function tep_db_input($string, $link = 'db_link') {
global $$link;
if (function_exists('mysql_real_escape_string')) {
return mysql_real_escape_string($string, $$link);
} elseif (function_exists('mysql_escape_string')) {
return mysql_escape_string($string);
}
return addslashes($string);
}
function tep_db_prepare_input($string) {
if (is_string($string)) {
return trim(tep_sanitize_string(stripslashes($string)));
} elseif (is_array($string)) {
reset($string);
while (list($key, $value) = each($string)) {
$string[$key] = tep_db_prepare_input($value);
}
return $string;
} else {
return $string;
}
}