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

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

          <bdo id='ptKil'></bdo><ul id='ptKil'></ul>
        <tfoot id='ptKil'></tfoot>

        如何判断列是否是使用 mysqli 的主键?

        时间:2023-09-24
          <tbody id='Cy1Os'></tbody>

        <legend id='Cy1Os'><style id='Cy1Os'><dir id='Cy1Os'><q id='Cy1Os'></q></dir></style></legend>
            • <small id='Cy1Os'></small><noframes id='Cy1Os'>

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

              1. <tfoot id='Cy1Os'></tfoot>

                  <bdo id='Cy1Os'></bdo><ul id='Cy1Os'></ul>
                • 本文介绍了如何判断列是否是使用 mysqli 的主键?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在将我的一些代码从旧的 mysql 扩展转换为 PHP 中的 mysqli 扩展.以前,使用mysql扩展,我曾使用过这样的代码来查找表中的主键:

                  I am converting some of my code from the older mysql extension to the mysqli extension in PHP. Previously, with the mysql extension, I had used some code like this to find the primary key in a table:

                  while ($i < mysql_num_fields($result)) {
                      $meta = mysql_fetch_field($result, $i);
                      if ($meta->primary_key == 1){ 
                          $primary_key = $meta->name; 
                      }
                      $i++;
                  }
                  

                  $meta->primary_key == 1 非常方便.

                  到目前为止,我已经转换为使用 mysqli 的代码:

                  So far I have converted to code to using mysqli:

                  while ($i < $result->field_count) {
                      $meta = $result->fetch_field;
                      if ($meta->primary_key == 1){ 
                          $primary_key = $meta->name; 
                      }
                      $i++;
                  }
                  

                  当然,通过查看文档这里我们可以看到 $meta->primary_key 在 mysqli 中不存在.我看到有一个 $meta->flags.这是我最好的猜测,虽然我不确定当我有主键时 flags 应该是什么值.

                  Of course, from looking at the docs here we can see that $meta->primary_key doesn't exist in mysqli. I see that there is a $meta->flags. This is my best guess, although i am not sure of what value flags should be when I have a primary key.

                  有谁知道我如何使用 mysqli 判断表的主键是哪一列?

                  Does anyone know how I tell which column is the primary key for a table using mysqli?

                  谢谢!

                  编辑这是一些工作代码:

                  //get primary key
                  $primary_key = '';
                  while ($meta = $result->fetch_field()) {
                      if ($meta->flags & MYSQLI_PRI_KEY_FLAG) { 
                          $primary_key = $meta->name; 
                      }
                  }
                  

                  推荐答案

                  您已经非常接近了,您将需要 flags 属性.

                  You were very close, you will need the flags property.

                  您正在寻找的标志是 MYSQLI_PRI_KEY_FLAG,意思是:

                  The flag you are looking for is MYSQLI_PRI_KEY_FLAG, which means:

                  字段是主索引的一部分

                  您可以使用以下内容测试此标志:

                  You can test for this flag with something like:

                  if ($meta->flags & MYSQLI_PRI_KEY_FLAG) { 
                    //it is a primary key!
                  }
                  

                  您在此处使用 & 作为 按位与运算符.

                  You are using & here as a Bitwise AND Operator.

                  这篇关于如何判断列是否是使用 mysqli 的主键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:检查 mysqli_query 是否返回任何值? 下一篇:bind_param() 有什么作用?

                  相关文章

                  最新文章

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

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

                    • <bdo id='EFnUn'></bdo><ul id='EFnUn'></ul>