downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

PDO::beginTransaction> <Les objets larges (LOB)
Last updated: Fri, 14 Aug 2009

view this page in

La classe PDO

Introduction

Représente une connexion entre PHP et un serveur de base de données.

Synopsis de la classe

PDO
PDO {
__construct ( string $dsn [, string $username [, string $password [, array $driver_options ]]] )
bool beginTransaction ( void )
bool commit ( void )
mixed errorCode ( void )
array errorInfo ( void )
int exec ( string $statement )
mixed getAttribute ( int $attribute )
array getAvailableDrivers ( void )
string lastInsertId ([ string $name= NULL ] )
PDOStatement prepare ( string $statement [, array $driver_options= array() ] )
PDOStatement query ( string $statement )
string quote ( string $string [, int $parameter_type= PDO::PARAM_STR ] )
bool rollBack ( void )
bool setAttribute ( int $attribute , mixed $value )
}

Sommaire

  • PDO::beginTransaction — Démarre une transaction
  • PDO::commit — Valide une transaction
  • PDO::__construct — Crée une instance PDO qui représente une connexion à la base
  • PDO::errorCode — Retourne le SQLSTATE associé avec la dernière opération sur la base de données
  • PDO::errorInfo — Retourne les informations associées à l'erreur lors de la dernière opération sur la base de données
  • PDO::exec — Exécute une requête SQL et retourne le nombre de lignes affectées
  • PDO::getAttribute — Récupère un attribut d'une connexion à une base de données
  • PDO::getAvailableDrivers — Retourne la liste des pilotes PDO disponibles
  • PDO::lastInsertId — Retourne l'identifiant de la dernière ligne insérée ou la valeur d'une séquence
  • PDO::prepare — Prépare une requête à l'exécution et retourne un objet
  • PDO::query — Exécute une requête SQL, retourne un jeu de résultats en tant qu'objet PDOStatement
  • PDO::quote — Protège une chaîne pour l'utiliser dans une requête SQL PDO
  • PDO::rollBack — Annule une transaction
  • PDO::setAttribute — Configure un attribut PDO


PDO::beginTransaction> <Les objets larges (LOB)
Last updated: Fri, 14 Aug 2009
 
add a note add a note User Contributed Notes
PDO
Megaloman
18-Feb-2009 04:03
"And storing username/password inside class is not a very good idea for production code."

Good idea is to store database connection settings in *.ini files but you have to restrict access to them. For example this way:

my_setting.ini:
[database]
driver = mysql
host = localhost
;port = 3306
schema = db_schema
username = user
password = secret

Database connection:
<?php
class MyPDO extends PDO
{
    public function
__construct($file = 'my_setting.ini')
    {
        if (!
$settings = parse_ini_file($file, TRUE)) throw new exception('Unable to open ' . $file . '.');
       
       
$dns = $settings['database']['driver'] .
       
':host=' . $settings['database']['host'] .
        ((!empty(
$settings['database']['port'])) ? (';port=' . $settings['database']['port']) : '') .
       
';dbname=' . $settings['database']['schema'];
       
       
parent::__construct($dns, $settings['database']['username'], $settings['database']['password']);
    }
}
?>

Database connection parameters are accessible via human readable ini file for those who screams even if they see one PHP/HTML/any_other command.
anrdaemon at freemail dot ru
22-Aug-2008 10:16
Keep in mind, you MUST NOT use 'root' user in your applications, unless your application designed to do a database maintenance.

And storing username/password inside class is not a very good idea for production code. You would need to edit the actual working code to change settings, which is bad.
schizo_mind at hotmail dot com
28-Jul-2008 07:00
<?php
class PDOConfig extends PDO {
   
    private
$engine;
    private
$host;
    private
$database;
    private
$user;
    private
$pass;
   
    public function
__construct(){
       
$this->engine = 'mysql';
       
$this->host = 'localhost';
       
$this->database = '';
       
$this->user = 'root';
       
$this->pass = '';
       
$dns = $this->engine.':dbname='.$this->database.";host=".$this->host;
       
parent::__construct( $dns, $this->user, $this->pass );
    }
}
?>

PDO::beginTransaction> <Les objets larges (LOB)
Last updated: Fri, 14 Aug 2009
 
 
show source | credits | sitemap | contact | advertising | mirror sites