我对使用$wpdb->prepare 函数用法。https://codex.wordpress.org/Class_Reference/wpdb#Placeholders 这个链接说prepare方法更好地保护sql注入。所以我用下面的代码来准备。
$query = $new_wpdb->prepare(
"INSERT INTO sym_data
( user_id, country, dob, height, weight, bmi )
VALUES ( %d, %s, %s, %d, %d, %f)",
$user_id, $country, $dob, $height, $weight, $bmi
);
$new_wpdb->query($query);
Check below code
$new_wpdb->insert(
\'sym_data\',
array(
\'user_id\' => $user_id,
\'country\' => $country,
\'dob\' => $dob,
\'height\' => $height,
\'weight\' => $weight,
\'bmi\' => $bmi,
),
array(
\'%d\',
\'%s\',
\'%s\',
\'%d\',
\'%d\',
\'%0.6f\'
)
);
我想知道这些代码块之间有什么区别。结果是一样的。
First code block is with prepare method
Second one is with placeholder