首页 php教程 php手册 zend 2.2 db select 使用例子

zend 2.2 db select 使用例子

Jun 13, 2016 am 11:30 AM
bar select use zend 使用 例子

<span <?php<br /><br />use</span><span  Zend\Db\Sql\Select;
 
</span><span //</span><span  basic table</span>
<span $select0</span> = <span new</span><span  Select;
</span><span $select0</span>->from('foo'<span );
</span><span //</span><span  'SELECT "foo".* FROM "foo"';
 
 
// table as TableIdentifier</span>
<span $select1</span> = <span new</span><span  Select;
</span><span $select1</span>->from(<span new</span> TableIdentifier('foo', 'bar'<span ));
</span><span //</span><span  'SELECT "bar"."foo".* FROM "bar"."foo"';
 
 
// table with alias</span>
<span $select2</span> = <span new</span><span  Select;
</span><span $select2</span>->from(<span array</span>('f' => 'foo'<span ));
</span><span //</span><span  'SELECT "f".* FROM "foo" AS "f"';
 
 
// table with alias with table as TableIdentifier</span>
<span $select3</span> = <span new</span><span  Select;
</span><span $select3</span>->from(<span array</span>('f' => <span new</span> TableIdentifier('foo'<span )));
</span><span //</span><span  'SELECT "f".* FROM "foo" AS "f"';
 
 
// columns</span>
<span $select4</span> = <span new</span><span  Select;
</span><span $select4</span>->from('foo')->columns(<span array</span>('bar', 'baz'<span ));
</span><span //</span><span  'SELECT "foo"."bar" AS "bar", "foo"."baz" AS "baz" FROM "foo"';
 
 
// columns with AS associative array</span>
<span $select5</span> = <span new</span><span  Select;
</span><span $select5</span>->from('foo')->columns(<span array</span>('bar' => 'baz'<span ));
</span><span //</span><span  'SELECT "foo"."baz" AS "bar" FROM "foo"';
 
 
// columns with AS associative array mixed</span>
<span $select6</span> = <span new</span><span  Select;
</span><span $select6</span>->from('foo')->columns(<span array</span>('bar' => 'baz', 'bam'<span ));
</span><span //</span><span  'SELECT "foo"."baz" AS "bar", "foo"."bam" AS "bam" FROM "foo"';
 
 
// columns where value is Expression, with AS</span>
<span $select7</span> = <span new</span><span  Select;
</span><span $select7</span>->from('foo')->columns(<span array</span>('bar' => <span new</span> Expression('COUNT(some_column)'<span )));
</span><span //</span><span  'SELECT COUNT(some_column) AS "bar" FROM "foo"';
 
 
// columns where value is Expression</span>
<span $select8</span> = <span new</span><span  Select;
</span><span $select8</span>->from('foo')->columns(<span array</span>(<span new</span> Expression('COUNT(some_column) AS bar'<span )));
</span><span //</span><span  'SELECT COUNT(some_column) AS bar FROM "foo"';
 
 
// columns where value is Expression with parameters</span>
<span $select9</span> = <span new</span><span  Select;
</span><span $select9</span>->from('foo')-><span columns(
    </span><span array</span><span (
        </span><span new</span><span  Expression(
            </span>'(COUNT(?) + ?) AS ?',
            <span array</span>('some_column', 5, 'bar'),
            <span array</span>(Expression::TYPE_IDENTIFIER, Expression::TYPE_VALUE, Expression::<span TYPE_IDENTIFIER)
        )
    )
);
</span><span //</span><span  'SELECT (COUNT("some_column") + ?) AS "bar" FROM "foo"';
//     array('column1' => 5);
//
// 'SELECT (COUNT("some_column") + \'5\') AS "bar" FROM "foo"';
 
// joins (plain)</span>
<span $select10</span> = <span new</span><span  Select;
</span><span $select10</span>->from('foo')-><span join</span>('zac', 'm = n'<span );
</span><span //</span><span  'SELECT "foo".*, "zac".* FROM "foo" INNER JOIN "zac" ON "m" = "n"';
 
 
// join with columns</span>
<span $select11</span> = <span new</span><span  Select;
</span><span $select11</span>->from('foo')-><span join</span>('zac', 'm = n', <span array</span>('bar', 'baz'<span ));
</span><span //</span><span  'SELECT "foo".*, "zac"."bar" AS "bar", "zac"."baz" AS "baz" FROM "foo" INNER JOIN "zac" ON "m" = "n"';
 
 
// join with alternate type</span>
<span $select12</span> = <span new</span><span  Select;
</span><span $select12</span>->from('foo')-><span join</span>('zac', 'm = n', <span array</span>('bar', 'baz'), Select::<span JOIN_OUTER);
</span><span //</span><span  'SELECT "foo".*, "zac"."bar" AS "bar", "zac"."baz" AS "baz" FROM "foo" OUTER JOIN "zac" ON "m" = "n"';
 
 
// join with column aliases</span>
<span $select13</span> = <span new</span><span  Select;
</span><span $select13</span>->from('foo')-><span join</span>('zac', 'm = n', <span array</span>('BAR' => 'bar', 'BAZ' => 'baz'<span ));
</span><span //</span><span  'SELECT "foo".*, "zac"."bar" AS "BAR", "zac"."baz" AS "BAZ" FROM "foo" INNER JOIN "zac" ON "m" = "n"';
 
 
// join with table aliases</span>
<span $select14</span> = <span new</span><span  Select;
</span><span $select14</span>->from('foo')-><span join</span>(<span array</span>('b' => 'bar'), 'b.foo_id = foo.foo_id'<span );
</span><span //</span><span  'SELECT "foo".*, "b".* FROM "foo" INNER JOIN "bar" AS "b" ON "b"."foo_id" = "foo"."foo_id"';
 
 
// where (simple string)</span>
<span $select15</span> = <span new</span><span  Select;
</span><span $select15</span>->from('foo')->where('x = 5'<span );
</span><span //</span><span  'SELECT "foo".* FROM "foo" WHERE x = 5';
 
 
// where (returning parameters)</span>
<span $select16</span> = <span new</span><span  Select;
</span><span $select16</span>->from('foo')->where(<span array</span>('x = ?' => 5<span ));
</span><span //</span><span  'SELECT "foo".* FROM "foo" WHERE x = ?';
//   array('where1' => 5);
//
// 'SELECT "foo".* FROM "foo" WHERE x = \'5\'';
 
 
// group</span>
<span $select17</span> = <span new</span><span  Select;
</span><span $select17</span>->from('foo')->group(<span array</span>('col1', 'col2'<span ));
</span><span //</span><span  'SELECT "foo".* FROM "foo" GROUP BY "col1", "col2"';</span>
 
 
<span $select18</span> = <span new</span><span  Select;
</span><span $select18</span>->from('foo')->group('col1')->group('col2'<span );
</span><span //</span><span  'SELECT "foo".* FROM "foo" GROUP BY "col1", "col2"';</span>
 
 
<span $select19</span> = <span new</span><span  Select;
</span><span $select19</span>->from('foo')->group(<span new</span> Expression('DAY(?)', <span array</span>('col1'), <span array</span>(Expression::<span TYPE_IDENTIFIER)));
</span><span //</span><span  'SELECT "foo".* FROM "foo" GROUP BY DAY("col1")';
 
 
// having (simple string)</span>
<span $select20</span> = <span new</span><span  Select;
</span><span $select20</span>->from('foo')->having('x = 5'<span );
</span><span //</span><span  'SELECT "foo".* FROM "foo" HAVING x = 5';
 
 
// having (returning parameters)</span>
<span $select21</span> = <span new</span><span  Select;
</span><span $select21</span>->from('foo')->having(<span array</span>('x = ?' => 5<span ));
</span><span //</span><span  'SELECT "foo".* FROM "foo" HAVING x = ?';
//   array('having1' => 5);
//
// 'SELECT "foo".* FROM "foo" HAVING x = \'5\'';
 
 
// order</span>
<span $select22</span> = <span new</span><span  Select;
</span><span $select22</span>->from('foo')->order('c1'<span );
</span><span //</span><span  'SELECT "foo".* FROM "foo" ORDER BY "c1" ASC';
 
 
// multiple order parts</span>
<span $select23</span> = <span new</span><span  Select;
</span><span $select23</span>->from('foo')->order(<span array</span>('c1', 'c2'<span ));
</span><span //</span><span  'SELECT "foo".* FROM "foo" ORDER BY "c1" ASC, "c2" ASC';
 
 
// mulitple order parts</span>
<span $select24</span> = <span new</span><span  Select;
</span><span $select24</span>->from('foo')->order(<span array</span>('c1' => 'DESC', 'c2' => 'Asc')); <span //</span><span  notice partially lower case ASC
// 'SELECT "foo".* FROM "foo" ORDER BY "c1" DESC, "c2" ASC';</span>
 
 
<span $select25</span> = <span new</span><span  Select;
</span><span $select25</span>->from('foo')->order(<span array</span>('c1' => 'asc'))->order('c2 desc'); <span //</span><span  notice partially lower case ASC
// 'SELECT "foo".* FROM "foo" ORDER BY "c1" ASC, "c2" DESC';
 
 
// limit</span>
<span $select26</span> = <span new</span><span  Select;
</span><span $select26</span>->from('foo')->limit(5<span );
</span><span //</span><span  'SELECT "foo".* FROM "foo" LIMIT ?';
//   array('limit' => 5);
//
// 'SELECT "foo".* FROM "foo" LIMIT \'5\'';
 
 
// limit with offset</span>
<span $select27</span> = <span new</span><span  Select;
</span><span $select27</span>->from('foo')->limit(5)->offset(10<span );
</span><span //</span><span  'SELECT "foo".* FROM "foo" LIMIT ? OFFSET ?';
//   array('limit' => 5, 'offset' => 10);
//
// 'SELECT "foo".* FROM "foo" LIMIT \'5\' OFFSET \'10\'';
 
 
// joins with a few keywords in the on clause</span>
<span $select28</span> = <span new</span><span  Select;
</span><span $select28</span>->from('foo')-><span join</span>('zac', '(m = n AND c.x) BETWEEN x AND y.z'<span );
</span><span //</span><span  'SELECT "foo".*, "zac".* FROM "foo" INNER JOIN "zac" ON ("m" = "n" AND "c"."x") BETWEEN "x" AND "y"."z"';
 
 
// order with compound name</span>
<span $select29</span> = <span new</span><span  Select;
</span><span $select29</span>->from('foo')->order('c1.d2'<span );
</span><span //</span><span  'SELECT "foo".* FROM "foo" ORDER BY "c1"."d2" ASC';
 
 
// group with compound name</span>
<span $select30</span> = <span new</span><span  Select;
</span><span $select30</span>->from('foo')->group('c1.d2'<span );
</span><span //</span><span  'SELECT "foo".* FROM "foo" GROUP BY "c1"."d2"';
 
 
// join with expression in ON part</span>
<span $select31</span> = <span new</span><span  Select;
</span><span $select31</span>->from('foo')-><span join</span>('zac', <span new</span> Expression('(m = n AND c.x) BETWEEN x AND y.z'<span ));
</span><span //</span><span  'SELECT "foo".*, "zac".* FROM "foo" INNER JOIN "zac" ON (m = n AND c.x) BETWEEN x AND y.z';
 
 
// subselects</span>
<span $select32subselect</span> = <span new</span><span  Select;
</span><span $select32subselect</span>->from('bar')->where->like('y', '%Foo%'<span );
</span><span $select32</span> = <span new</span><span  Select;
</span><span $select32</span>->from(<span array</span>('x' => <span $select32subselect</span><span ));
</span><span //</span><span  'SELECT "x".* FROM (SELECT "bar".* FROM "bar" WHERE "y" LIKE ?) AS "x"';
// 'SELECT "x".* FROM (SELECT "bar".* FROM "bar" WHERE "y" LIKE \'%Foo%\') AS "x"';
 
 
// use array in where, predicate in where</span>
<span $select33</span> = <span new</span><span  Select;
</span><span $select33</span>->from('table')->columns(<span array</span>('*'))->where(<span array</span><span (
    </span>'c1' => <span null</span>,
    'c2' => <span array</span>(1, 2, 3),
    <span new</span> \Zend\Db\Sql\Predicate\IsNotNull('c3'<span )
));
</span><span //</span><span  'SELECT "table".* FROM "table" WHERE "c1" IS NULL AND "c2" IN (?, ?, ?) AND "c3" IS NOT NULL';
// 'SELECT "table".* FROM "table" WHERE "c1" IS NULL AND "c2" IN (\'1\', \'2\', \'3\') AND "c3" IS NOT NULL';
 
 
// Expression objects in order</span>
<span $select34</span> = <span new</span><span  Select;
</span><span $select34</span>->from('table')->order(<span array</span><span (
    </span><span new</span> Expression('isnull(?) DESC', <span array</span>('name'), <span array</span>(Expression::TYPE_IDENTIFIER)),
    'name'<span 
));
</span><span //</span><span  'SELECT "table".* FROM "table" ORDER BY isnull("name") DESC, "name" ASC';
 
 
// join with Expression object in COLUMNS part (ZF2-514)</span>
<span $select35</span> = <span new</span><span  Select;
</span><span $select35</span>->from('foo')->columns(<span array</span>())-><span join</span>('bar', 'm = n', <span array</span>('thecount' => <span new</span> Expression("COUNT(*)"<span )));
</span><span //</span><span  'SELECT COUNT(*) AS "thecount" FROM "foo" INNER JOIN "bar" ON "m" = "n"';
 
 
// multiple joins with expressions</span>
<span $select36</span> = <span new</span><span  Select;
</span><span $select36</span>->from('foo'<span )
    </span>-><span join</span>('tableA', <span new</span> Predicate\Operator('id', '=', 1<span ))
    </span>-><span join</span>('tableB', <span new</span> Predicate\Operator('id', '=', 2<span ))
    </span>-><span join</span>('tableC', <span new</span> Predicate\PredicateSet(<span array</span><span (
        </span><span new</span> Predicate\Operator('id', '=', 3),
        <span new</span> Predicate\Operator('number', '>', 20<span )
    )));
</span><span //</span><span  'SELECT "foo".*, "tableA".*, "tableB".*, "tableC".* FROM "foo" '
//   'INNER JOIN "tableA" ON "id" = :join1part1 INNER JOIN "tableB" ON "id" = :join2part1 '
//   'INNER JOIN "tableC" ON "id" = :join3part1 AND "number" > :join3part2';
//
// 'SELECT "foo".*, "tableA".*, "tableB".*, "tableC".* FROM "foo" '
//   'INNER JOIN "tableA" ON "id" = \'1\' INNER JOIN "tableB" ON "id" = \'2\' '
//   'INNER JOIN "tableC" ON "id" = \'3\' AND "number" > \'20\'';</span>
登录后复制

 

本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

热AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

AI Hentai Generator

AI Hentai Generator

免费生成ai无尽的。

热门文章

R.E.P.O.能量晶体解释及其做什么(黄色晶体)
2 周前 By 尊渡假赌尊渡假赌尊渡假赌
仓库:如何复兴队友
4 周前 By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island冒险:如何获得巨型种子
3 周前 By 尊渡假赌尊渡假赌尊渡假赌

热工具

记事本++7.3.1

记事本++7.3.1

好用且免费的代码编辑器

SublimeText3汉化版

SublimeText3汉化版

中文版,非常好用

禅工作室 13.0.1

禅工作室 13.0.1

功能强大的PHP集成开发环境

Dreamweaver CS6

Dreamweaver CS6

视觉化网页开发工具

SublimeText3 Mac版

SublimeText3 Mac版

神级代码编辑软件(SublimeText3)

如何使用磁力链接 如何使用磁力链接 Feb 18, 2024 am 10:02 AM

磁力链接是一种用于下载资源的链接方式,相比传统的下载方式更为便捷和高效。使用磁力链接可以通过点对点的方式下载资源,而不需要依赖中介服务器。本文将介绍磁力链接的使用方法及注意事项。一、什么是磁力链接磁力链接是一种基于P2P(Peer-to-Peer)协议的下载方式。通过磁力链接,用户可以直接连接到资源的发布者,从而完成资源的共享和下载。与传统的下载方式相比,磁

Win11 Xbox Game Bar怎么彻底卸载掉?分享Xbox Game Bar卸载方法 Win11 Xbox Game Bar怎么彻底卸载掉?分享Xbox Game Bar卸载方法 Feb 10, 2024 am 09:21 AM

Win11XboxGameBar怎么彻底卸载掉?XboxGameBar是系统中自带的游戏平台,它提供了用于游戏录制、截图和社交功能的工具,不过很是占用内存,也不好卸载,一些小伙伴想要将它卸载掉,但是不这道怎么彻底卸载,下面就来为大家介绍一下吧。方法一、使用Windows终端1、按【Win+X】组合键,或【右键】点击任务栏上的【Windows开始菜单】,在打开的的菜单项中,选择【终端管理员】。2、用户账户控制窗口,你要允许此应用对你的设备进行更改吗?点击【是】。3、执行以下命令:Get-AppxP

如何使用mdf和mds文件 如何使用mdf和mds文件 Feb 19, 2024 pm 05:36 PM

mdf文件和mds文件怎么用随着计算机技术的不断进步,我们可以通过多种方式来存储和共享数据。在数字媒体领域,我们经常会遇到一些特殊的文件格式。在这篇文章中,我们将讨论一种常见的文件格式——mdf和mds文件,并介绍它们的使用方法。首先,我们需要了解mdf文件和mds文件的含义。mdf是CD/DVD镜像文件的扩展名,而mds文件则是mdf文件的元数据文件。

crystaldiskmark是什么软件?-crystaldiskmark如何使用? crystaldiskmark是什么软件?-crystaldiskmark如何使用? Mar 18, 2024 pm 02:58 PM

CrystalDiskMark是一款适用于硬盘的小型HDD基准测试工具,可以快速测量顺序和随机读/写速度。接下来就让小编为大家介绍一下CrystalDiskMark,以及crystaldiskmark如何使用吧~一、CrystalDiskMark介绍CrystalDiskMark是一款广泛使用的磁盘性能测试工具,用于评估机械硬盘和固态硬盘(SSD)的读写速度和随机I/O性能。它是一款免费的Windows应用程序,并提供用户友好的界面和各种测试模式来评估硬盘驱动器性能的不同方面,并被广泛用于硬件评

foobar2000怎么下载?-foobar2000怎么使用 foobar2000怎么下载?-foobar2000怎么使用 Mar 18, 2024 am 10:58 AM

foobar2000是一款能随时收听音乐资源的软件,各种音乐无损音质带给你,增强版本的音乐播放器,让你得到更全更舒适的音乐体验,它的设计理念是将电脑端的高级音频播放器移植到手机上,提供更加便捷高效的音乐播放体验,界面设计简洁明了易于使用它采用了极简的设计风格,没有过多的装饰和繁琐的操作能够快速上手,同时还支持多种皮肤和主题,根据自己的喜好进行个性化设置,打造专属的音乐播放器支持多种音频格式的播放,它还支持音频增益功能根据自己的听力情况调整音量大小,避免过大的音量对听力造成损害。接下来就让小编为大

网易邮箱大师怎么用 网易邮箱大师怎么用 Mar 27, 2024 pm 05:32 PM

网易邮箱,作为中国网民广泛使用的一种电子邮箱,一直以来以其稳定、高效的服务赢得了用户的信赖。而网易邮箱大师,则是专为手机用户打造的邮箱软件,它极大地简化了邮件的收发流程,让我们的邮件处理变得更加便捷。那么网易邮箱大师该如何使用,具体又有哪些功能呢,下文中本站小编将为大家带来详细的内容介绍,希望能帮助到大家!首先,您可以在手机应用商店搜索并下载网易邮箱大师应用。在应用宝或百度手机助手中搜索“网易邮箱大师”,然后按照提示进行安装即可。下载安装完成后,我们打开网易邮箱账号并进行登录,登录界面如下图所示

小爱音箱怎么使用 小爱音箱怎么连接手机 小爱音箱怎么使用 小爱音箱怎么连接手机 Feb 22, 2024 pm 05:19 PM

长按音箱的播放键后,在软件中连接wifi即可使用。教程适用型号:小米12系统:EMUI11.0版本:小爱同学2.4.21解析1首先找到音箱的播放键,长按进入配网模式。2在手机上的小爱音箱软件中登录小米账号,点击添加新的小爱音箱。3输入wifi的名称和密码后,即可呼唤小爱同学进行使用了。补充:小爱音箱有什么功能1小爱音箱有系统功能、社交功能、娱乐功能、知识功能、生活功能、智能家庭、训练计划。总结/注意事项手机要提前安装好小爱同学APP,方便连接和使用。

百度网盘app怎么用 百度网盘app怎么用 Mar 27, 2024 pm 06:46 PM

在如今云存储已经成为我们日常生活和工作中不可或缺的一部分。百度网盘作为国内领先的云存储服务之一,凭借其强大的存储功能、高效的传输速度以及便捷的操作体验,赢得了广大用户的青睐。而且无论你是想要备份重要文件、分享资料,还是在线观看视频、听取音乐,百度网盘都能满足你的需求。但是很多用户们可能对百度网盘app的具体使用方法还不了解,那么这篇教程就将为大家详细介绍百度网盘app如何使用,还有疑惑的用户们就快来跟着本文详细了解一下吧!百度云网盘怎么用:一、安装首先,下载并安装百度云软件时,请选择自定义安装选

See all articles