PHP mysqli bind_param 文本类型
对于将用户评论转储到 MySQL 表中的反馈表单,我不确定用户提供的反馈文本使用哪种 bind_param 类型(MySQL 字段类型 = 文本)
For a feedback form that will dump user comments into a MySQL table, I'm unsure which bind_param type to use for the user-supplied feedback text (MySQL field type = text)
function sql_ins_feedback($dtcode,$custip,$name,$email,$subject,$feedback)
{
global $mysqli ;
if($stmt = $mysqli->prepare("INSERT INTO feedback (dtcode,custip,name,email,subject,feedback) VALUES (?,?,?,?,?,?)"))
{
$stmt->bind_param("ssssss", $dtcode,$custip,$name,$email,$subject,$feedback);
$stmt->execute() ;
$stmt->close() ;
}
}
还是这个?
$stmt->bind_param("sssssb", $dtcode,$custip,$name,$email,$subject,$feedback);
那么,blob 类型是否是文本字段的正确 bind_param 类型?
So, is the blob type the correct bind_param type for a text field?
bind_param("s") 类型的大小限制是多少?
What is the size limit for a bind_param("s") type?
在使用 bind_param("b") 时还有什么必须做的吗?该手册(以及我在某处/某时阅读的其他内容)表明 blob 类型的处理方式有所不同——我应该知道什么?
Is there anything else one must do when using bind_param("b") ? The manual (and something else I read somewhere/sometime) suggests blob types are treated differently -- anything I should know?
谢谢
推荐答案
这实际上取决于 Mysql 服务器.整个查询中组合的所有数据的默认最大大小为 1mb.请参阅:http://dev.mysql.com/doc/refman/5.1/en/packet-too-large.html
This actually depends on the Mysql server. The default max size for all data combined in the entire query is 1mb. See: http://dev.mysql.com/doc/refman/5.1/en/packet-too-large.html
如果您的数据组合在 "max_allowed_packet" 阈值,只需使用s"作为任何文本字段的绑定类型.事实上,您通常可以对任何字段类型(日期、浮点数等)使用s".
If your data combined is under that "max_allowed_packet" threshold, just use "s" for the binding type for any text field. Infact, you can usually get away with using "s" for any field type at all (date, float, etc).
如果您要插入的整个条目的总长度超过 1mb(或您将其重置为的任何值),您将需要使用 mysqli_stmt::send_long_data 方法和b"绑定类型以分块发送此特定字段.
If your entire entry combined that you want to insert is over 1mb (or whatever you reset it to) in length, you'll want to use mysqli_stmt::send_long_data method and the "b" binding type to send this particular field in chunks.
相关文章