I don't want to use Symfony2 doctrine. Instead want to write own data classes to handle MySQL queries. So is there any way that directly sql queries can be executed. Most article in google talks about Doctrine or MySQL+Doctrine.
2 Answers
If you don't want to use Doctrine ORM or even Doctrine DBAL, absolutley nothing stopes you from using PDO/MySQLi directly.
Define PDO instance as DIC service:
<service id="pdo" class="PDO"> <argument>dns</argument> <argument>user</argument> <argument>password</argument> <call method="setAttribute"> <argument>2</argument> <!-- use exception for error handling --> </call> </service>Pass PDO instance for each service that requires database connection:
<service id="my.custom.service" class="My\Custom\Service"> <argument type="service" id="pdo" /> </serivce> --- namespace My\Custom; class Service { public function __construct(PDO $pdo) { } }