0

Following the transition from a Windows environment to Linux (but always in sql server), I find some difficulties.

I tried different method : exec, execute, query -> same error

My class bd is like that :

<?php

class BD {

// ---- Partie Privé : Les propriétés --------
var $connexion, $connectBase, $db;


// ---- Constructeur de la class -------------

function BD() {

    //paramètres de connexion
    if(file_exists("config/config.inc.php"))
        include("config/config.inc.php");
    elseif(file_exists("../config/config.inc.php"))
        include("../config/config.inc.php");
    $db=new PDO("dblib:host=servername;dbname=dbname", 'login', 'pass');
    $this->db = $db;
    $db->debug=true;

//Fin du constructeur
}

And in this class i have this function :

function exereq($requete) {


    $resultat = $this->$db->Exec($requete) or die("Erreur lors de 
 l'execution de la requ&ecirc;te : <br>".$requete."<br>".$this->db- 
>errorInfo());
    //test de la requete
    if(!$resultat) {
            $this->message("Problème lors de l'execution de la 
 requ&ecirc;te : <br>".$requete."<br>".$this->db->errorInfo());
    }

    return $resultat;
}

In an other file, i call it like that :

require_once("config/config.inc.php");
require_once("includes/bd.class.php");
require_once("includes/functions.php");

global $bd;
$bd = new BD();

if(isset($_GET['ORDER_ID']) && $_GET['ORDER_ID'] != '') {

$select_order       = "SELECT ORDER_NUMBER FROM EP_ORDER WHERE 
EP_ORDER.ORDER_ID = ".$_GET['ORDER_ID'];
$res_select_order   = $bd->exereq($select_order);`

I have the error PHP Fatal error: Cannot access empty property in ftvdev/impmat/includes/bd.class.php on line 63. The line where the function is executed.

talou
  • 1
  • 1
  • 1
    It should be `$this->db`, not `$this->$db`. – aynber Jan 30 '19 at 13:36
  • Does https://stackoverflow.com/questions/14920216/php-fatal-error-cannot-access-empty-property help? – Nico Haase Jan 30 '19 at 13:42
  • yes there was a mistake about $this->db, not $this->$db But there were finally a lot of things to change – talou Jan 30 '19 at 20:49
  • Now the function query is public function query($sql_str) { $m = "query"; if (preg_match('/INSERT|UPDATE|DELETE/',$sql_str)) { $m = "exec"; } try { $res = $this->db->{$m}($sql_str); } catch(PDOException $e) { throw new Exception("Erreur SQL: ".var_dump($this->db->errorInfo())); die(); } if ($m == "exec") { return $res; } return $res->fetchAll(PDO::FETCH_ASSOC); } – talou Jan 30 '19 at 20:51

0 Answers0