Home
Docs
GitHub
Pricing
Blog
Log In

Run Sandworm Audit for your App

Get started
Hold on, we're currently generating a fresh version of this report

doctrine/orm 3.1.1

Object-Relational-Mapper for PHP
Package summary
Share
0
issues
0
licenses
Package created
10 Oct 2011
Version published
21 Mar 2024
Maintainers
2
Total deps
0
Direct deps
0
License
MIT
Generating a report...
Hold on while we generate a fresh audit report for this package.

Frequently Asked Questions

What does doctrine/orm do?

The Doctrine ORM (Object-Relational-Mapper) is a highly powerful database abstraction tool for PHP 7.1+ that allows for transparent persistence of PHP objects. It offers a proprietary Object Oriented SQL dialect, known as Doctrine Query Language (DQL), which was inspired by Hibernate’s HQL. This allows developers to write database queries with more flexibility, without creating redundant code.

How do you use doctrine/orm?

Using Doctrine ORM in a PHP application involves a few key steps. First, you need to install it using Composer. This can be achieved by running the following command in your terminal: composer require doctrine/orm.

Once installed, you can setup the EntityManager, which is the primary access point to ORM functionality provided by Doctrine:

<?php
require_once "vendor/autoload.php";

use Doctrine\ORM\Tools\Setup;
use Doctrine\ORM\EntityManager;

$paths = array("/path/to/entity-files");
$isDevMode = false;

// the connection configuration
$dbParams = array(
    'driver'   => 'pdo_mysql',
    'user'     => 'root',
    'password' => 'password',
    'dbname'   => 'mydb',
);

$config = Setup::createAnnotationMetadataConfiguration($paths, $isDevMode);
$entityManager = EntityManager::create($dbParams, $config);

And then interact with your database using Doctrine's API:

<?php
// src/Product.php
/** @Entity */
class Product
{
    /**
     * @var int
     * @Id @Column(type="integer") @GeneratedValue
     */
    private $id;

    /**
     * @var string
     * @Column(type="string")
     */
    private $name;
    
    //.. (add getters and setters here)
}

In the above code the notation /** @Entity */ is a Doctrine annotation marking this class as an entity class.

More about associative mappings, fetching objects, querying, and more can be found in the official documentation.

Where are the doctrine/orm docs?

For complete details on how to use the Doctrine ORM, you can refer to the project's extensive documentation. This comprehensive guide provides detailed instructions and examples to help you harness the full power of the Doctrine ORM in your PHP applications.