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 Dernière révision Les deux révisions suivantes | ||
utilisateurs:hypathie:tutos:php_connexion_mysql [08/07/2021 17:03] Hypathie [Objet PDO] |
utilisateurs:hypathie:tutos:php_connexion_mysql [08/07/2021 17:22] Hypathie |
||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
- | ====== PHP connexion mysql ====== | + | ====== PHP singleton de connexion mysql ====== |
* Objet : code php de connexion | * Objet : code php de connexion | ||
Ligne 107: | Ligne 107: | ||
class MysqlSingleton | class MysqlSingleton | ||
{ | { | ||
- | const SQL_USER = 'root'; | + | const SQL_USER = 'toto'; |
const SQL_HOST = 'localhost'; | const SQL_HOST = 'localhost'; | ||
const SQL_PASS = '********'; | const SQL_PASS = '********'; | ||
Ligne 125: | Ligne 125: | ||
{ | { | ||
self::$connect = new PDO('mysql:dbname='.self::SQL_DTB.';host='.self::SQL_HOST,self::SQL_USER ,self::SQL_PASS); | 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"; | echo "CREATION CONNEXION PDO MYSQL"; | ||
} | } | ||
Ligne 179: | Ligne 178: | ||
public function logSqlErreur() | public function logSqlErreur() | ||
{ | { | ||
+ | // TODO | ||
} | } | ||
Ligne 302: | Ligne 302: | ||
?> | ?> | ||
</code> | </code> | ||
+ | |||
+ | === Exécution du code === | ||
+ | |||
+ | <note tip> | ||
+ | Comme attendu, nous avons bien qu'une seule fois "CREATION CONNEXION PDO MYSQL" ! | ||
+ | </note> | ||
+ | |||
+ | * Dans le navigateur : **localhost/testSingleton/index.php** | ||
+ | |||
+ | Voir le wiki prendre en main apache pour installer l'alias ou le virtualhost "testSingleton". | ||
+ | |||
+ | <code retour> | ||
+ | CREATION CONNEXION PDO MYSQL | ||
+ | Constructeur GestionPDO.php calling by /home/hypathie/www/Test/public/data_tree.php. | ||
+ | Constructeur DAO_dataTree.php | ||
+ | |||
+ | /home/hypathie/www/Test/public/index.php:10: | ||
+ | array (size=2) | ||
+ | 'name' => string 'USA' (length=3) | ||
+ | 0 => string 'USA' (length=3) | ||
+ | |||
+ | |||
+ | Constructeur GestionPDO.php calling by /home/hypathie/www/Test/public/data_users.php. | ||
+ | Constructeur DAO_dataUsers.php | ||
+ | |||
+ | /home/hypathie/www/Test/public/\index.php:15: | ||
+ | array (size=2) | ||
+ | 'name' => string 'Jean-Marc' (length=9) | ||
+ | 0 => string 'Jean-Marc' (length=9) | ||
+ | |||
+ | </code> | ||
+ | |||
+ |