PHP mysqli bind_param类型的文本 [英] PHP mysqli bind_param type for text

查看:83
本文介绍了PHP mysqli bind_param类型的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于将用户注释转储到MySQL表中的反馈表,我不确定用于用户提供的反馈文本的哪种bind_param类型(MySQL字段类型= 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类型?

bind_param("s")类型的大小限制是多少?

使用bind_param("b")时,还有其他必须做的事情吗?该手册(以及我在某处/某时间读到的其他内容)建议对Blob类型的处理方式有所不同-我应该知道什么?

谢谢

解决方案

这实际上取决于Mysql服务器.整个查询中组合的所有数据的默认最大大小为1mb.参见: http://dev.mysql.com/doc /refman/5.1/en/packet-too-large.html

如果合并的数据在该下, max_allowed_pa​​cket" 阈值,只需将"s"用作任何文本字段的绑定类型.实际上,通常对于所有字段类型(日期,浮点等),都可以不使用"s".

如果您要插入的整个条目的总长度超过1mb(或将其重置为任何长度),则需要使用

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() ; 
    }
}

OR THIS?

        $stmt->bind_param("sssssb", $dtcode,$custip,$name,$email,$subject,$feedback);

So, is the blob type the correct bind_param type for a text field?

What is the size limit for a bind_param("s") type?

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?

Thanks

解决方案

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

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).

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.

这篇关于PHP mysqli bind_param类型的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆