Symfony2 implement a summary of how to obtain data from the database, Symfony2 summary _php Tutorial

Source: Internet
Author: User






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 ...


  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.