2014-12-03 21:08:08 +01:00
|
|
|
<?php
|
2014-12-17 13:48:03 +01:00
|
|
|
/**
|
|
|
|
* This software is governed by the CeCILL-B license. If a copy of this license
|
|
|
|
* is not distributed with this file, you can obtain one at
|
|
|
|
* http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.txt
|
|
|
|
*
|
|
|
|
* Authors of STUdS (initial project): Guilhem BORGHESI (borghesi@unistra.fr) and Raphaël DROZ
|
|
|
|
* Authors of Framadate/OpenSondate: Framasoft (https://github.com/framasoft)
|
|
|
|
*
|
|
|
|
* =============================
|
|
|
|
*
|
|
|
|
* Ce logiciel est régi par la licence CeCILL-B. Si une copie de cette licence
|
|
|
|
* ne se trouve pas avec ce fichier vous pouvez l'obtenir sur
|
|
|
|
* http://www.cecill.info/licences/Licence_CeCILL-B_V1-fr.txt
|
|
|
|
*
|
|
|
|
* Auteurs de STUdS (projet initial) : Guilhem BORGHESI (borghesi@unistra.fr) et Raphaël DROZ
|
|
|
|
* Auteurs de Framadate/OpenSondage : Framasoft (https://github.com/framasoft)
|
|
|
|
*/
|
2014-12-03 21:08:08 +01:00
|
|
|
namespace Framadate;
|
|
|
|
|
2015-01-18 16:14:45 +01:00
|
|
|
use PDO;
|
|
|
|
|
2014-12-21 23:48:22 +01:00
|
|
|
class FramaDB {
|
2014-12-03 21:08:08 +01:00
|
|
|
/**
|
|
|
|
* PDO Object, connection to database.
|
|
|
|
*/
|
|
|
|
private $pdo = null;
|
|
|
|
|
2014-12-21 23:48:22 +01:00
|
|
|
function __construct($connection_string, $user, $password) {
|
2014-12-03 21:08:08 +01:00
|
|
|
$this->pdo = new \PDO($connection_string, $user, $password);
|
2014-12-05 01:08:38 +01:00
|
|
|
$this->pdo->setAttribute(\PDO::ATTR_DEFAULT_FETCH_MODE, \PDO::FETCH_OBJ);
|
|
|
|
$this->pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
|
2014-12-03 21:08:08 +01:00
|
|
|
}
|
|
|
|
|
2014-12-31 01:33:56 +01:00
|
|
|
/**
|
|
|
|
* @return \PDO Connection to database
|
|
|
|
*/
|
|
|
|
function getPDO() {
|
|
|
|
return $this->pdo;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Find all tables in database.
|
|
|
|
*
|
|
|
|
* @return array The array of table names
|
|
|
|
*/
|
|
|
|
function allTables() {
|
2014-12-21 23:48:22 +01:00
|
|
|
$result = $this->pdo->query('SHOW TABLES');
|
2014-12-03 21:08:08 +01:00
|
|
|
$schemas = $result->fetchAll(\PDO::FETCH_COLUMN);
|
2014-12-29 21:54:07 +01:00
|
|
|
|
2014-12-31 01:33:56 +01:00
|
|
|
return $schemas;
|
2014-12-03 21:08:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function prepare($sql) {
|
|
|
|
return $this->pdo->prepare($sql);
|
|
|
|
}
|
|
|
|
|
|
|
|
function beginTransaction() {
|
|
|
|
$this->pdo->beginTransaction();
|
|
|
|
}
|
|
|
|
|
|
|
|
function commit() {
|
|
|
|
$this->pdo->commit();
|
|
|
|
}
|
|
|
|
|
2014-12-23 00:30:05 +01:00
|
|
|
function rollback() {
|
|
|
|
$this->pdo->rollback();
|
|
|
|
}
|
|
|
|
|
|
|
|
function errorCode() {
|
|
|
|
return $this->pdo->errorCode();
|
|
|
|
}
|
|
|
|
|
|
|
|
function errorInfo() {
|
|
|
|
return $this->pdo->errorInfo();
|
|
|
|
}
|
|
|
|
|
2014-12-03 21:08:08 +01:00
|
|
|
function query($sql) {
|
|
|
|
return $this->pdo->query($sql);
|
|
|
|
}
|
2014-12-07 23:12:08 +01:00
|
|
|
|
2015-04-03 00:11:36 +02:00
|
|
|
public function lastInsertId() {
|
|
|
|
return $this->pdo->lastInsertId();
|
2015-01-06 23:52:52 +01:00
|
|
|
}
|
2014-12-03 21:08:08 +01:00
|
|
|
}
|