pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

    • <bdo id='61FEg'></bdo><ul id='61FEg'></ul>

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

      <small id='61FEg'></small><noframes id='61FEg'>

      <legend id='61FEg'><style id='61FEg'><dir id='61FEg'><q id='61FEg'></q></dir></style></legend>

      1. SQL 從多個表中選擇 *

        SQL Select * from multiple tables(SQL 從多個表中選擇 *)

        <legend id='VF9vO'><style id='VF9vO'><dir id='VF9vO'><q id='VF9vO'></q></dir></style></legend>
                <tfoot id='VF9vO'></tfoot>
                  <bdo id='VF9vO'></bdo><ul id='VF9vO'></ul>
                    <tbody id='VF9vO'></tbody>

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

                • <small id='VF9vO'></small><noframes id='VF9vO'>

                  本文介紹了SQL 從多個表中選擇 *的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  使用 PHP/PDO/MySQL 是否可以在對多個表進行選擇并且返回的數組鍵是完全限定的以避免列名沖突時對列使用通配符?

                  Using PHP/PDO/MySQL is it possible to use a wildcard for the columns when a select is done on multiple tables and the returned array keys are fully qualified to avoid column name clash?

                  示例:

                  SELECT * from table1, table2;

                  給出:

                  數組鍵是'table1.id'、'table2.id'、'table1.name'等

                  Array keys are 'table1.id', 'table2.id', 'table1.name' etc.

                  我嘗試了SELECT table1.*,table2.* ...",但返回的數組鍵不是完全限定的,因此具有相同名稱的列發生沖突并被覆蓋.

                  I tried "SELECT table1.*,table2.* ..." but the returned array keys were not fully qualified so columns with the same name clashed and were overwritten.

                  推薦答案

                  是的,你可以.最簡單的方法是使用 pdo,盡管至少有一些其他擴展可以使用它.

                  Yes, you can. The easiest way is with pdo, although there's at least a few other extensions which are capable of it.

                  在 PDO 對象上設置屬性,而不是 PDOStatment.

                  Set the attribute on the PDO object, not the PDOStatment.

                  $PDO->setAttribute(PDO::ATTR_FETCH_TABLE_NAMES, true);
                  

                  就是這樣.然后你會得到像 $row['myTable.myColumn'] 這樣的關聯數組鍵.如果您也獲取對象(例如通過 PDO::FETCH_OBJECT),它也可以工作,所以要小心,因為您需要訪問像 $obj->{'myTable.myColumn'}<這樣的屬性/代碼>

                  That's it. Then you get associative array keys like $row['myTable.myColumn']. It works if you fetch an object too (eg via PDO::FETCH_OBJECT) so beware, because you need to access the properties like $obj->{'myTable.myColumn'}

                  *手冊說 PDO::ATTR_FETCH_TABLE_NAMES 屬性僅受某些驅動程序支持.如果上述方法不起作用,則可能可以代替.

                  *The manual says the PDO::ATTR_FETCH_TABLE_NAMES attribute is only supported by certain drivers. If the above doesn't work, this might work instead.

                  $pdoStatement->setFetchMode(PDO::FETCH_NUM);
                  $pdoStatement->execute();
                  //build our associative array keys
                  $qualifiedColumnNames = array();
                  for ($i = 0; $i < $pdoStatement->columnCount(); $i++) {
                      $columnMeta = $pdoStatement->getColumnMeta($i);
                      $qualifiedColumnNames[] = "$columnMeta[table].$columnMeta[name]";
                  }
                  
                  //fetch results and combine with keys
                  while ($row = $pdoStatement->fetch()) {
                      $qualifiedRow = array_combine($qualifiedColumnNames, $row);
                      print_r($qualifiedRow);
                  }
                  

                  <小時>

                  相同的基本模式用于其他數據庫擴展


                  Same basic pattern is used for other database extensions

                  $res = mysql_query($sql);
                  //build our associative array keys
                  $qualifiedColumnNames = array();
                  for ($i = 0; $i < mysql_num_fields($res); $i++) {
                      $columnMeta = mysql_fetch_field($res, $i);
                      $qualifiedColumnNames[] = "$columnMeta[table].$columnMeta[name]";
                  }
                  
                  //fetch results and combine with keys
                  while ($row = mysql_fetch_row($res)) {
                      $qualifiedRow = array_combine($qualifiedColumnNames, $row);
                      print_r($qualifiedRow);
                  }
                  

                  <小時>

                  mysqli

                  $res = $mysqli->query($sql);
                  //build our associative array keys
                  $qualifiedColumnNames = array();
                  foreach ($res->fetch_fields() as $columnMeta) {
                      $qualifiedColumnNames[] = "{$columnMeta->table}.{$columnMeta->name}";
                  }
                  
                  //fetch results and combine with keys
                  while ($row = $res->fetch_row()) {
                      $qualifiedRow = array_combine($qualifiedColumnNames, $row);
                      print_r($qualifiedRow);
                  }
                  

                  這也適用于表別名(在 php 7.1 中測試) - 限定列名將使用表別名.

                  This should also work with table aliases (tested in php 7.1) - the qualified column name will use the table alias.

                  這篇關于SQL 從多個表中選擇 *的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  MySQLi prepared statement amp; foreach loop(MySQLi準備好的語句amp;foreach 循環)
                  Is mysqli_insert_id() gets record from whole server or from same user?(mysqli_insert_id() 是從整個服務器還是從同一用戶獲取記錄?)
                  PHP MySQLi doesn#39;t recognize login info(PHP MySQLi 無法識別登錄信息)
                  mysqli_select_db() expects exactly 2 parameters(mysqli_select_db() 需要 2 個參數)
                  Php mysql pdo query: fill up variable with query result(Php mysql pdo 查詢:用查詢結果填充變量)
                  MySQLI 28000/1045 Access denied for user #39;root#39;@#39;localhost#39;(MySQLI 28000/1045 用戶“root@“localhost的訪問被拒絕)
                • <small id='zr5nu'></small><noframes id='zr5nu'>

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

                        <tbody id='zr5nu'></tbody>

                      • <bdo id='zr5nu'></bdo><ul id='zr5nu'></ul>
                          • <tfoot id='zr5nu'></tfoot>
                            主站蜘蛛池模板: 耐高温风管_耐高温软管_食品级软管_吸尘管_钢丝软管_卫生级软管_塑料波纹管-东莞市鑫翔宇软管有限公司 | SEO网站优化,关键词排名优化,苏州网站推广-江苏森歌网络 | 成都思迪机电技术研究所-四川成都思迪编码器 | 耐高温硅酸铝板-硅酸铝棉保温施工|亿欧建设工程 | 真空干燥烘箱_鼓风干燥箱 _高低温恒温恒湿试验箱_光照二氧化碳恒温培养箱-上海航佩仪器 | 环境模拟实验室_液体-气体控温机_气体控温箱_无锡双润冷却科技有限公司 | COD分析仪|氨氮分析仪|总磷分析仪|总氮分析仪-圣湖Greatlake | Brotu | 关注AI,Web3.0,VR/AR,GPT,元宇宙区块链数字产业 | 广州监控安装公司_远程监控_安防弱电工程_无线wifi覆盖_泉威安防科技 | 传动滚筒,改向滚筒-淄博建凯机械科技有限公司 | 紧急切断阀_气动切断阀_不锈钢阀门_截止阀_球阀_蝶阀_闸阀-上海上兆阀门制造有限公司 | 合景一建-无尘车间设计施工_食品医药洁净车间工程装修总承包公司 | 聚合氯化铝厂家-聚合氯化铝铁价格-河南洁康环保科技 | 钣金加工厂家-钣金加工-佛山钣金厂-月汇好 | 奥运星-汽车性能网评-提供个性化汽车资讯 | 超声波电磁流量计-液位计-孔板流量计-料位计-江苏信仪自动化仪表有限公司 | 陕西安闸机-伸缩门-车牌识别-广告道闸——捷申达门业科技 | 锻造液压机,粉末冶金,拉伸,坩埚成型液压机定制生产厂家-山东威力重工官方网站 | 汽车整车综合环境舱_军标砂尘_盐雾试验室试验箱-无锡苏南试验设备有限公司 | 安全光栅|射频导纳物位开关|音叉料位计|雷达液位计|两级跑偏开关|双向拉绳开关-山东卓信机械有限公司 | 宝元数控系统|对刀仪厂家|东莞机器人控制系统|东莞安川伺服-【鑫天驰智能科技】 | 耐火浇注料-喷涂料-浇注料生产厂家_郑州市元领耐火材料有限公司 耐力板-PC阳光板-PC板-PC耐力板 - 嘉兴赢创实业有限公司 | 合景一建-无尘车间设计施工_食品医药洁净车间工程装修总承包公司 | ETFE膜结构_PTFE膜结构_空间钢结构_膜结构_张拉膜_浙江萬豪空间结构集团有限公司 | 软文世界-软文推广-软文营销-新闻稿发布-一站式软文自助发稿平台 | 金属雕花板_厂家直销_价格低-山东慧诚建筑材料有限公司 | POS机官网 - 拉卡拉POS机免费办理|官网在线申请入口 | 合肥礼品公司-合肥礼品定制-商务礼品定制公司-安徽柏榽商贸有限公司 | 预制围墙_工程预制围墙_天津市瑞通建筑材料有限公司 | 北京三友信电子科技有限公司-ETC高速自动栏杆机|ETC机柜|激光车辆轮廓测量仪|嵌入式车道控制器 | 振动筛-交叉筛-螺旋筛-滚轴筛-正弦筛-方形摇摆筛「新乡振动筛厂家」 | 中央空调维修、中央空调保养、螺杆压缩机维修-苏州东菱空调 | 蜂窝块状沸石分子筛-吸附脱硫分子筛-萍乡市捷龙环保科技有限公司 | 哈希余氯测定仪,分光光度计,ph在线监测仪,浊度测定仪,试剂-上海京灿精密机械有限公司 | 水压力传感器_数字压力传感器|佛山一众传感仪器有限公司|首页 | 交通气象站_能见度检测仪_路面状况监测站- 天合环境科技 | 砂磨机_立式纳米砂磨机_实验室砂磨机-广州儒佳化工设备厂家 | 植筋胶-粘钢胶-碳纤维布-碳纤维板-环氧砂浆-加固材料生产厂家-上海巧力建筑科技有限公司 | 进口试验机价格-进口生物材料试验机-西安卡夫曼测控技术有限公司 | 快速门厂家批发_PVC快速卷帘门_高速门_高速卷帘门-广州万盛门业 快干水泥|桥梁伸缩缝止水胶|伸缩缝装置生产厂家-广东广航交通科技有限公司 | 【孔氏陶粒】建筑回填陶粒-南京/合肥/武汉/郑州/重庆/成都/杭州陶粒厂家 |