欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Symfony2實(shí)現(xiàn)從數(shù)據(jù)庫獲取數(shù)據(jù)的方法小結(jié)

 更新時(shí)間:2016年03月18日 10:05:48   作者:Surfin  
這篇文章主要介紹了Symfony2實(shí)現(xiàn)從數(shù)據(jù)庫獲取數(shù)據(jù)的方法,結(jié)合實(shí)例形式總結(jié)分析了常用的Symfony數(shù)據(jù)庫查詢技巧,需要的朋友可以參考下

本文實(shí)例講述了Symfony2實(shí)現(xiàn)從數(shù)據(jù)庫獲取數(shù)據(jù)的方法。分享給大家供大家參考,具體如下:

假設(shè)有一張表: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);

結(jié)果為:

Tom

示例2:

$conn = $this->getDoctrine()->getConnection();
$data = $conn->fetchArray("SELECT name, color FROM test");
echo '<pre>'; print_r($data);

結(jié)果為:

Array
(
  [0]=>Tom
  [1]=>blue
)

示例3:

$conn = $this->getDoctrine()->getConnection();
$data = $conn->fetchAssoc("SELECT name, color FROM test");
echo '<pre>'; print_r($data);

結(jié)果為:

Array
(
  [name]=>Tom
  [color]=>blue
)

示例4:

$conn = $this->getDoctrine()->getConnection();
$data = $conn->fetchAll("SELECT name, color FROM test");
echo '<pre>'; print_r($data);

結(jié)果為:

Array
(
  [0] => Array
    (
      [name]=>Tom
      [color]=>blue
    )
  [1] => Array
    (
      [name]=>Lily
      [color]=>red
    )
)

希望本文所述對大家基于Symfony框架的PHP程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論