Symfony2 summarizes the methods used to obtain data from the database, and symfony2. Symfony2: a summary of how to obtain data from the database. symfony2 this article describes how to obtain data from the database in Symfony2. Share it with you for your reference. for details, refer to Symfony2's method summary for getting data from the database and symfony2's summary.
This example describes how to obtain data from a database using Symfony2. We will share this with you for your reference. The details are as follows:
Suppose there is a table: test, field: name, color;
There are two records:
Tom blue
Lily red
Example 1:
$ Conn = $ this-> getDoctrine ()-> getConnection (); $ data = $ conn-> fetchcolumn ("SELECT name, color FROM test"); echo''; print_r($data);
Result:
Tom
Example 2:
$ Conn = $ this-> getDoctrine ()-> getConnection (); $ data = $ conn-> fetchArray ("SELECT name, color FROM test"); echo''; print_r($data);
Result:
Array( [0]=>Tom [1]=>blue)
Example 3:
$ Conn = $ this-> getDoctrine ()-> getConnection (); $ data = $ conn-> fetchAssoc ("SELECT name, color FROM test"); echo''; print_r($data);
Result:
Array( [name]=>Tom [color]=>blue)
Example 4:
$ Conn = $ this-> getDoctrine ()-> getConnection (); $ data = $ conn-> fetchAll ("SELECT name, color FROM test"); echo''; print_r($data);
Result:
Array( [0] => Array ( [name]=>Tom [color]=>blue ) [1] => Array ( [name]=>Lily [color]=>red ))
I hope this article will help you design PHP programs based on the Symfony framework.
Articles you may be interested in:
- Symfony2 joint query implementation method
- Symfony2 create page instance details
- Analysis on date usage in twig of symfony2.4
- Session and cookie usage in Symfony2
- Symfony2 framework learning Notes
- Symfony2 study notes plugin format analysis
- System route details for Symfony2 study notes
- A detailed explanation of the controller usage of Symfony2 learning Notes
- Template usage of Symfony2 learning Notes
- How to install a third-party Bundles instance in Symfony2
- Symfony2 function usage example analysis
Examples in this article describes how to obtain data from a database using Symfony2. Share it with you for your reference, as shown in...