小编use*_*788的帖子

OSCommerce tep_db_input vs tep_db_prepare_input

我正在开发一个使用OSCommerce和MySQL的项目,我很困惑何时应该使用tep_db_input()或tep_db_prepare_input().我假设我应该在插入/更新的任何字符串周围使用tep_db_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)."'
        )"
    );
}
Run Code Online (Sandbox Code Playgroud)

它是否正确?

编辑::如果有人不熟悉这些功能,以下是他们的定义:

function tep_sanitize_string($string) {
    $patterns = array ('/ +/','/[<>]/');
    $replace = array (' ', '_');
    return preg_replace($patterns, $replace, trim($string));
}

function tep_db_input($string, $link …
Run Code Online (Sandbox Code Playgroud)

php mysql oscommerce

9
推荐指数
1
解决办法
3133
查看次数

标签 统计

mysql ×1

oscommerce ×1

php ×1