Home > Backend Development > PHP Tutorial > Summary of how Symfony2 implements obtaining data from the database, symfony2 summary_PHP tutorial

Summary of how Symfony2 implements obtaining data from the database, symfony2 summary_PHP tutorial

WBOY
Release: 2016-07-12 08:56:26
Original
895 people have browsed it

A summary of Symfony2's method of obtaining data from the database, a summary of symfony2

The example in this article describes the method of Symfony2's method of obtaining data from the database. Share it with everyone for your reference, the details are as follows:

Suppose there is a table: test, fields: 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 '<pre class="brush:php;toolbar:false">'; print_r($data);

Copy after login

The result is:

Tom

Copy after login

Example 2:

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

Copy after login

The result is:

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

Copy after login

Example 3:

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

Copy after login

The result is:

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

Copy after login

Example 4:

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

Copy after login

The result is:

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

Copy after login

I hope this article will be helpful to everyone’s PHP program design based on the Symfony framework.

Articles you may be interested in:

  • Symfony2 joint query implementation method
  • Detailed explanation of creating page instances in Symfony2
  • Analysis of date usage in twig of symfony2.4
  • Summary of session and cookie usage in Symfony2
  • Detailed explanation of form usage in Symfony2 framework study notes
  • Plug-in format analysis of Symfony2 study notes
  • Symfony2 study notes Detailed explanation of system routing
  • Detailed explanation of controller usage in Symfony2 study notes
  • Detailed explanation of template usage in Symfony2 study notes
  • Detailed explanation of installation of third-party Bundles instances in Symfony2
  • Symfony2 Analysis of function usage examples

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1111906.htmlTechArticleSymfony2 summary of the method of obtaining data from the database, symfony2 summary This article describes the example of Symfony2 method of obtaining data from the database . Share it with everyone for your reference, specifically...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template