本文实例讲述了symfony2实现从数据库获取数据的方法。分享给大家供大家参考,具体如下:
假设有一张表:test, 字段:name,color;
有2条记录:
tom blue
lily red
示例1:
$conn = $this->getdoctrine()->getconnection();
$data = $conn->fetchcolumn("select name, color from test");
echo '<pre>'; print_r($data);
结果为:
tom
示例2:
$conn = $this->getdoctrine()->getconnection();
$data = $conn->fetcharray("select name, color from test");
echo '<pre>'; print_r($data);
结果为:
array
(
[0]=>tom
[1]=>blue
)
示例3:
$conn = $this->getdoctrine()->getconnection();
$data = $conn->fetchassoc("select name, color from test");
echo '<pre>'; print_r($data);
结果为:
array
(
[name]=>tom
[color]=>blue
)
示例4:
$conn = $this->getdoctrine()->getconnection();
$data = $conn->fetchall("select name, color from test");
echo '<pre>'; print_r($data);
结果为:
array
(
[0] => array
(
[name]=>tom
[color]=>blue
)
[1] => array
(
[name]=>lily
[color]=>red
)
)
希望本文所述对大家基于symfony框架的php程序设计有所帮助。
【说明】:本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:)!