Bonjour, j'utilise les 2 fichiers ci-dessous pour me connecter à une base de données mysql.
Le premier s'appelle config.php et contient les Identifiants pour la base de données.
Le deuxième est le fichier PDO (pdo2.php):
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7 <?php // Identifiants pour la base de données. Nécessaires a PDO2. define('SQL_DSN', 'host=mysql.hostinger.fr;mysql:dbname=u*******_nomBDD'); define('SQL_USERNAME', 'u*****_name'); define('SQL_PASSWORD', 'MDP'); ?>
Ça marche très bien avec Wampserver mais lorsque je transfère les fichiers sur un serveur en ligne, j'obtiens ce message d'erreur :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 <?php /** * Classe implémentant le singleton PDO */ class PDO2 extends PDO { private static $_instance; /* Constructeur : héritage public obligatoire par héritage de PDO */ public function __construct() { } // End of PDO2::_construct() */ /* Singleton */ public static function getInstance() { if (!isset(self::$_instance)) { try { self::$_instance = new PDO(SQL_DSN, SQL_USERNAME, SQL_PASSWORD); } catch (PDOException $e) { echo $e; }} return self::$_instance; } // End of PDO2::getInstance() */ } // end of file */ ?>
exception 'PDOException' with message 'could not find driver' in /home/u*****/public_html/pdo2.php:18
Stack trace:
#0 /home/u*******/public_html/pdo2.php(18): PDO->__construct('host=mysql.host...', 'u******_name...', 'Mdp***')
#1 /home/u*******/public_html/requestFichierName.php(14): PDO2::getInstance()
#2 {main}<br />
<b>Fatal error</b>: Call to a member function prepare() on a non-object in <b>/home/u********/public_html/requestFichierName.php</b> on line <b>27</b><br />
Pourriez-vous me dire d'où vient l'erreur SVP? Merci beaucoup d'avance,
Cordialement
Arsène
Partager