Symfony2实现从数据库获取数据的方法小结
本文实例讲述了Symfony2实现从数据库获取数据的方法。分享给大家供大家参考,具体如下:
假设有一张表:test,字段:name,color;
有2条记录:
Tomblue
Lilyred
示例1:
$conn=$this->getDoctrine()->getConnection();
$data=$conn->fetchcolumn("SELECTname,colorFROMtest");
echo'<pre>';print_r($data);
结果为:
Tom
示例2:
$conn=$this->getDoctrine()->getConnection();
$data=$conn->fetchArray("SELECTname,colorFROMtest");
echo'<pre>';print_r($data);
结果为:
Array ( [0]=>Tom [1]=>blue )
示例3:
$conn=$this->getDoctrine()->getConnection();
$data=$conn->fetchAssoc("SELECTname,colorFROMtest");
echo'<pre>';print_r($data);
结果为:
Array ( [name]=>Tom [color]=>blue )
示例4:
$conn=$this->getDoctrine()->getConnection();
$data=$conn->fetchAll("SELECTname,colorFROMtest");
echo'<pre>';print_r($data);
结果为:
Array ( [0]=>Array ( [name]=>Tom [color]=>blue ) [1]=>Array ( [name]=>Lily [color]=>red ) )
希望本文所述对大家基于Symfony框架的PHP程序设计有所帮助。
热门推荐
1 训练狗狗憋尿
2 狗狗追踪训练
3 狗狗训练要多少钱
5 深圳狗狗训练
6 训练狗狗唤回
7 狗狗叫怎么训练
8 狗狗训练班
10 狗狗社会化训练
11 狗狗叫回训练
12 广州狗狗训练学校
13 狗狗训练躺下
14 狗狗随行训练
15 训练狗狗巡回
16 狗狗要怎么训练
17 狗狗喂食训练
18 训练狗狗躺下