hello , I have a question in php data objects.
how to write pdo functions in my own class?
I would using pdo in my own classes but I don't have any way for that
Edited by promehdioh, 20 February 2011 - 10:11 AM.
hello , I have a question in php data objects.
how to write pdo functions in my own class?
I would using pdo in my own classes but I don't have any way for that
Edited by promehdioh, 20 February 2011 - 10:11 AM.
|
|
|
<?php
$dbh = new PDO('mysql:host=localhost;dbname=test', $user, $pass);
?>
Check the manual for more info
class MyDB extends PDO {
$m_lastquery = '';
public function __construct ($dsn, $username, $password, $driver_options=null){
parent::__construct($dsn, $username, $password, $driver_options);
}
public function doSomethingWithPdo($query) {
$this->m_lastquery = parent::prepare($query);
$this->m_lastquery->execute();
}
}
// example use
$query = "INSERT INTO table VALUES (1, 2, 3)";
$mydb = new MyDB("localhost", "root", "password");
$mydb->doSomethingWithPdo($query);I would brush up on object oriented programming with PHP to get the most out of working with the classes.
Edited by Alexander, 23 February 2011 - 06:52 PM.
0 members, 1 guests, 0 anonymous users