0

PHP: how to connect with database with PDO in object oriented php

How can i connect to my database with PDO method in OOP And how can i make class to make query later on in database?

9th Apr 2018, 2:05 PM
aadil
4 Antworten
+ 4
The try - catch statement and errmode_exceptions are optional but its good to have something to handle an error.
9th Apr 2018, 4:18 PM
Toni Isotalo
Toni Isotalo - avatar
+ 5
try { $db = new PDO("mysql:host=127.0.0.1;dbname=name", "root", ""); $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } catch(PDOException $e) { die("Connection failed"); }
9th Apr 2018, 2:20 PM
Toni Isotalo
Toni Isotalo - avatar
+ 1
Thanks toni
9th Apr 2018, 2:21 PM
aadil
0
I figured that out :) Thanks again
9th Apr 2018, 5:26 PM
aadil