Vous n'êtes pas identifié(e).
L'icône rouge permet de télécharger chaque page du wiki visitée au format
PDF et la grise au format ODT →
Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentes Révision précédente Prochaine révision | Révision précédente Prochaine révision Les deux révisions suivantes | ||
utilisateurs:hypathie:tutos:php_connexion_mysql [08/07/2021 16:38] Hypathie [BDD mysql/mariadb] |
utilisateurs:hypathie:tutos:php_connexion_mysql [08/07/2021 16:50] Hypathie [Objet PDO] |
||
---|---|---|---|
Ligne 89: | Ligne 89: | ||
===== Objet PDO ===== | ===== Objet PDO ===== | ||
+ | <code> | ||
+ | └───public | ||
+ | |_ MysqlSingleton.php | ||
+ | |_ gestionnairePDO.php | ||
+ | |_ data_users.php | ||
+ | |_ data_tree.php | ||
+ | |_ index.php | ||
+ | </code> | ||
+ | === MysqlSingleton.php === | ||
+ | <code php> | ||
+ | <?php | ||
+ | error_reporting(E_ALL); | ||
+ | ini_set('display_errors', '1'); | ||
+ | class MysqlSingleton | ||
+ | { | ||
+ | const SQL_USER = 'root'; | ||
+ | const SQL_HOST = 'localhost'; | ||
+ | const SQL_PASS = 'arawak'; | ||
+ | const SQL_DTB = 'nath_test'; | ||
+ | private static $connect = null; | ||
+ | private $message = null; | ||
+ | |||
+ | private function __construct() | ||
+ | { | ||
+ | // A singleton should not be instanced ! | ||
+ | } | ||
+ | protected static function firstConnexion() | ||
+ | { | ||
+ | if(is_null(self::$connect )) | ||
+ | { | ||
+ | try | ||
+ | { | ||
+ | self::$connect = new PDO('mysql:dbname='.self::SQL_DTB.';host='.self::SQL_HOST,self::SQL_USER ,self::SQL_PASS); | ||
+ | //self::$connect = new PDO('mysql:host=localhost;dbname=nath_test;charset=utf8','root', 'arawak'); | ||
+ | echo "CREATION CONNEXION PDO MYSQL"; | ||
+ | } | ||
+ | catch(PDOException $e) | ||
+ | { | ||
+ | $this->message=$e->getMessage(); | ||
+ | die(); | ||
+ | } | ||
+ | } | ||
+ | return self::$connect; | ||
+ | } | ||
+ | |||
+ | protected function getStatus() | ||
+ | { | ||
+ | return !is_null(self::$connect); | ||
+ | } | ||
+ | |||
+ | protected function getErreurMessage() | ||
+ | { | ||
+ | return $this->message; | ||
+ | } | ||
+ | |||
+ | protected function disconnectMysql() | ||
+ | { | ||
+ | self::$connect = null; | ||
+ | } | ||
+ | } | ||
+ | </code> | ||
+ | === gestionnairePDO.php === | ||
+ | |||
+ | <code php> | ||
+ | |||
+ | </code> | ||
+ | |||
+ | === data_users.php === | ||
+ | |||
+ | <code php> | ||
+ | |||
+ | </code> | ||
+ | |||
+ | === data_tree.php === | ||
+ | |||
+ | <code php> | ||
+ | |||
+ | </code> | ||
+ | |||
+ | === index.php === | ||
+ | |||
+ | <code php> | ||
+ | |||
+ | </code> |