The examples in this paper describe the method of Symfony2 to from a database. Share to everyone for your reference, as follows:
Suppose there is a table: Test, field: Name,color;
There are 2 records:
Tom Blue
Lily Red
Example 1:
$conn = $this->getdoctrine ()->getconnection (); $data = $conn->fetchcolumn ("Select name, color from test"); Echo '
'; Print_r ($data);
The result is:
Tom
Example 2:
$conn = $this->getdoctrine ()->getconnection (); $data = $conn->fetcharray ("Select name, color from test"); Echo '
'; Print_r ($data);
The result is:
Array ( [0]=>tom [1]=>blue]
Example 3:
$conn = $this->getdoctrine ()->getconnection (); $data = $conn->fetchassoc ("Select name, color from test"); Echo '
'; Print_r ($data);
The result is:
Array ( [Name]=>tom [Color]=>blue]
Example 4:
$conn = $this->getdoctrine ()->getconnection (); $data = $conn->fetchall ("Select name, color from test"); Echo '
'; Print_r ($data);
The result is:
Array ([ 0] = = Array ( [Name]=>tom [Color]=>blue ) [1] = = Array ( [name ]=>lily [color]=>red )]
It is hoped that this article is helpful to the PHP program design based on Symfony framework.
Articles you may be interested in:
- Implementation method of Symfony2 Federated query
- Symfony2 Creating a Page instance
- Analysis of date usage in twig of symfony2.4
- Summary of Symfony2 's session and cookie usage
- Symfony2 Framework Learning Notes Form usage
- Analysis of plugin format of Symfony2 learning notes
- Symfony2 Study Notes System routing
- Symfony2 study notes of the controller usage detailed
- Symfony2 Study Notes Template usage detailed
- Symfony2 installing a third-party bundles instance
- An example analysis of Symfony2 function usage
http://www.bkjia.com/PHPjc/1111906.html www.bkjia.com true http://www.bkjia.com/PHPjc/1111906.html techarticle Symfony2 implementation of the method to from the database summary, Symfony2 Summary in this paper, Symfony2 implementation of the method to from the database. Share to everyone for your reference, specific as ...