CMMI Level 3 Company
Doctrine: The Doctrine is a set of PHP libraries primarily focused on providing persistance services and related functionality. Its prize projects are an Object Relational Mapper (ORM) and the Database Abstraction Layer it is built on top of.
One of Doctrine's key features is the option to write database queries in a proprietary object oriented SQL dialect called Doctrine Query Language (DQL).
Doctrine instatllation :
// Including Doctine Base class
spl_autoload_register ( array ('Doctrine','autoload'));
//create the singleton Doctrine_Manager instance and assign it to a variable named $manager:
$manager = Doctrine_Manager::getInstance();
// Connecting to database
$conn = Doctrine_Manager::connection('mysql://' . $userName . ':' . $password . '@' . $hostName . '/' . $dbName,'connection1');
//Code to Autoload models no need to manually include generated classes
3. Doctrine will generate models automatically for every table in our DB. For this feature we have to include one line after the above lines.
4. After this we can use those models and write the queries using Doctrine Query language(DQL).
5. Where ever we want to use the models or database related query we want to include the models like
require_once($MyClass . 'Ads.php');
Here 'Ads' is the table name and Ads.php is the model that automatically generated.
Insert Query using DQL :
Let us take Ads is our model
$insert = new Ads();
$insert->name = ‘ad’;
Select query using DQL :
$selectQuery = Doctrine_Query::create()
To Fetch the array
$selectName = $selectQuery->fetchArray();
Update query using DQL :
$updateAdQuery = Doctrine_Query::create()
To execute the query
Delete Query using DQL :
$deleteAdQuery = Doctrine_Query::create()
Writing Inner JOIN query using DQL :
$innerJoinQuery = Doctrine_Query::create()
->where('s1.s_v_id = ?',1);
To fetch the data
$selectRes = $innerJoinQuery->fetchArray();
Aug 07, 2017
Jul 24, 2017
Jun 13, 2017
May 31, 2017
Drop us a line and we'll get in touch with you as quick as we can