• I have include this into my header.php

    <?php
    $connectionString ="mysql:dbname=labo_game;";
    $connectionString .="host=localhost;";
    $connectionUser ="root";
    $connectionPassword="";
    
    try{
    $bdd= new PDO($connectionString, $connectionUser, $connectionPassword); echo "connect ok";}
    catch(Exception $e){echo "erreur de connexion à la bdd";} //si on arrive pas à se connecter à la bdd
    ?>

    and I have “connect ok”… my object should be created

    in my index.php, I have :

    <?php
    
    			$recuperation_batiments = $bdd->prepare('SELECT * FROM planete WHERE id_joueur= :id'); // ajouter la selection de la planète
    			$recuperation_batiments->execute(array( 'id' => 5));
    			$recuperation_batiments2 = $recuperation_batiments->fetch();
    
    			$batiment_recherche = $recuperation_batiments2['batiment_recherche'];
    
    ?>

    but the page returns me an error :

    Fatal error: Call to a member function prepare() on a non-object in C:\wamp\www\folder\wordpress-mu\wp-content\themes\Creation Theme\home.php on line 44

    Is it possible to use pdo with wordpress, and …do you see any error in my code ?

    EDIT : okay I’ve find my problem : we can’t include the variables into the header.php
    someone know how I can put that file in the header and not lose my variables (- I think this is because I’m using get_header(); -)

  • The topic ‘is it possible to use PDO in wordpress’ is closed to new replies.