<legend id='lbLZQ'><style id='lbLZQ'><dir id='lbLZQ'><q id='lbLZQ'></q></dir></style></legend>

  • <tfoot id='lbLZQ'></tfoot>

    <small id='lbLZQ'></small><noframes id='lbLZQ'>

      <bdo id='lbLZQ'></bdo><ul id='lbLZQ'></ul>
    <i id='lbLZQ'><tr id='lbLZQ'><dt id='lbLZQ'><q id='lbLZQ'><span id='lbLZQ'><b id='lbLZQ'><form id='lbLZQ'><ins id='lbLZQ'></ins><ul id='lbLZQ'></ul><sub id='lbLZQ'></sub></form><legend id='lbLZQ'></legend><bdo id='lbLZQ'><pre id='lbLZQ'><center id='lbLZQ'></center></pre></bdo></b><th id='lbLZQ'></th></span></q></dt></tr></i><div id='lbLZQ'><tfoot id='lbLZQ'></tfoot><dl id='lbLZQ'><fieldset id='lbLZQ'></fieldset></dl></div>

        PHP PDO::bindParam() 数据类型..它是如何工作的?

        时间:2023-09-25

          <tbody id='Zc1pd'></tbody>
        <legend id='Zc1pd'><style id='Zc1pd'><dir id='Zc1pd'><q id='Zc1pd'></q></dir></style></legend><tfoot id='Zc1pd'></tfoot>

                • <bdo id='Zc1pd'></bdo><ul id='Zc1pd'></ul>
                • <i id='Zc1pd'><tr id='Zc1pd'><dt id='Zc1pd'><q id='Zc1pd'><span id='Zc1pd'><b id='Zc1pd'><form id='Zc1pd'><ins id='Zc1pd'></ins><ul id='Zc1pd'></ul><sub id='Zc1pd'></sub></form><legend id='Zc1pd'></legend><bdo id='Zc1pd'><pre id='Zc1pd'><center id='Zc1pd'></center></pre></bdo></b><th id='Zc1pd'></th></span></q></dt></tr></i><div id='Zc1pd'><tfoot id='Zc1pd'></tfoot><dl id='Zc1pd'><fieldset id='Zc1pd'></fieldset></dl></div>

                  <small id='Zc1pd'></small><noframes id='Zc1pd'>

                  本文介绍了PHP PDO::bindParam() 数据类型..它是如何工作的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我想知道 bindParam() 中数据类型的声明是什么(或bindValue()) 用于...

                  I'm wondering what the declaration of the data type in bindParam() (or bindValue()) is used for...

                  我的意思是,我认为如果我定义一个整数参数 (PDO::PARAM_INT),该参数必须转换为一个整数,例如

                  I mean, I thought that if I define an integer argument (PDO::PARAM_INT), the argument must be converted to an integer, something like

                  $delete->bindParam(1, $kill, PDO::PARAM_INT);
                  // should work like
                  $delete->bindParam(1, (int)$kill);
                  

                  或者至少在参数不是声明的类型时抛出错误.但事实并非如此.

                  or at least throw an error if the argument is not of the declared type. But this is not the case.

                  谷歌搜索,我发现在 php.net 档案中:

                  Googling around, I found that in the php.net archive:

                  大家好,

                  我目前正在研究 PDO.确切地在 bindParam() 函数上.第三参数 data_type 似乎在这里强制值的类型?但当我尝试时:

                  I am currently working on PDO. Exactly on the bindParam() function. The third parameter data_type seems to be here to force the type of the value ? But when I try :

                  $sql = "INSERT INTO produit (idproduit, nom, marque) VALUES (NULL, :nom, :marque)";
                  $stmt = $dbh->prepare($sql);
                  $nom = 'Testarossa'; $marque = 'Ferrari' ;
                  $stmt->BindValue(':marque',$marque) ;
                  $stmt->BindParam(':nom',$nom,PDO::PARAM_INT) ;
                  
                  $stmt->execute(); $nom = '250 GTO' ;
                  $stmt->execute(); ?>
                  

                  我希望有一个 PHP我的数据库中的错误或整数.但在我的数据库中,我有:

                  I was expecting to have either a PHP error or an interger in my database. But in my DB I have :

                  22 Testarossa 法拉利 23 250 GTO法拉利

                  22 Testarossa Ferrari 23 250 GTO Ferrari

                  这意味着如果我没有改变有没有第三个参数.或者也许我错过了什么.有人可以吗对我多一点?或者只是有人可以告诉我在哪里可以找到信息关于它.

                  It mean that it didn't change if I have the third parameter or not. Or perhaps I miss something. Can someone tole me more ? Or just can someone told me where I can find information about it.

                  问候,

                  赛勒斯

                  这正是我的情况.我的想法哪里出了问题?

                  That is exactly my situation. Where are my thoughts going wrong?

                  推荐答案

                  在其他语言的其他数据库抽象框架中,它可用于确保您对内联值进行正确的转义(对于驱动程序不支持正确的绑定参数)并通过确保数字被适当地二进制打包来提高网络效率(给定协议支持).它看起来像在 PDO 中,它没有做太多事情.

                  In other DB abstraction frameworks in other languages it can be used for things like making sure you're doing the proper escaping for in-lining values (for drivers that don't support proper bound parameters) and improving network efficiency by making sure numbers are binary packed appropriately (given protocol support). It looks like in PDO, it doesn't do much.

                     if (PDO_PARAM_TYPE(param->param_type) == PDO_PARAM_STR && param->max_value_len <= 0 && ! ZVAL_IS_NULL(param->parameter)) {
                                  if (Z_TYPE_P(param->parameter) == IS_DOUBLE) {
                                          char *p;
                                          int len = spprintf(&p, 0, "%F", Z_DVAL_P(param->parameter));
                                          ZVAL_STRINGL(param->parameter, p, len, 0);
                                  } else {
                                          convert_to_string(param->parameter);
                                  }
                          } else if (PDO_PARAM_TYPE(param->param_type) == PDO_PARAM_INT && Z_TYPE_P(param->parameter) == IS_BOOL) {
                                  convert_to_long(param->parameter);
                          } else if (PDO_PARAM_TYPE(param->param_type) == PDO_PARAM_BOOL && Z_TYPE_P(param->parameter) == IS_LONG) {
                                  convert_to_boolean(param->parameter);
                          }
                  

                  所以,如果你说它是一个 STR(或者你什么都不说,因为这是默认的)并且你的数据的内部类型是一个 double 那么它会使用一种方法将它变成一个字符串,如果它不是一个double 然后它将使用不同的方法将其转换为字符串.

                  So, if you say it is a STR (or if you say nothing at all as that is the default) and your data's internal type is a double then it will turn it into a string using one method, if it's not a double then it will convert it to a string using a different method.

                  如果你说它是一个 int 但它实际上是一个 bool 那么它会将它转换为 long.

                  If you say it's an int but it is really a bool then it will convert it to a long.

                  如果你说它是一个布尔值,但它实际上是一个数字,那么它会将其转换为真正的布尔值.

                  If you say it's a bool but it's really a number then it will convert it to a true boolean.

                  这就是我看到的(快速)查看 stmt 源代码的全部内容,我想一旦您将参数传递给驱动程序,它们就可以发挥额外的作用.所以,我猜你得到的只是一点点做对,以及司机之间的大量行为模糊和差异.

                  This is really all I saw (quickly) looking at the stmt source, I imagine once you pass the parameters into the driver they can do additional magic. So, I'd guess that all you get is a little bit of do the right and a whole lot of behavior ambiguity and variance between drivers.

                  这篇关于PHP PDO::bindParam() 数据类型..它是如何工作的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何解析“必须是字符串的实例,字符串给定& 下一篇:哪个 MySQL 数据类型用于 IP 地址?

                  相关文章

                  最新文章

                • <i id='PfnjU'><tr id='PfnjU'><dt id='PfnjU'><q id='PfnjU'><span id='PfnjU'><b id='PfnjU'><form id='PfnjU'><ins id='PfnjU'></ins><ul id='PfnjU'></ul><sub id='PfnjU'></sub></form><legend id='PfnjU'></legend><bdo id='PfnjU'><pre id='PfnjU'><center id='PfnjU'></center></pre></bdo></b><th id='PfnjU'></th></span></q></dt></tr></i><div id='PfnjU'><tfoot id='PfnjU'></tfoot><dl id='PfnjU'><fieldset id='PfnjU'></fieldset></dl></div>
                  • <bdo id='PfnjU'></bdo><ul id='PfnjU'></ul>

                • <legend id='PfnjU'><style id='PfnjU'><dir id='PfnjU'><q id='PfnjU'></q></dir></style></legend>
                    <tfoot id='PfnjU'></tfoot>

                    <small id='PfnjU'></small><noframes id='PfnjU'>