Catchable fatal error: Object of class PDOStatement could not be converted to string in on line 24

0

I want to pass the results of the two queries in the same variable so that I can show it in a table, but I throw that error in the code, the code is as follows:

    <?php
include("../BD-Config/config.php");
session_start();
// liste des événements
 $json = array();
 // requête qui récupère les événements
 $requete = "SELECT * FROM evenement JOIN mis_contactos JOIN vehiculos
            ON id_mec = id_meca AND id_usuario = id_user JOIN empresa WHERE evenement.id_user=1 AND empresa.id_meca=evenement.id_mec AND
                evenement.id_vehiculo = vehiculos.id_vehiculo AND evenement.estado_cita>0 AND evenement.estado_cita<6 ORDER BY id DESC";

$querreque = "SELECT * FROM cita_autolavado JOIN vehiculos JOIN empresa WHERE id_user = 1 AND vehiculos.id_vehiculo = cita_autolavado.id_vehiculo AND id_meca = cita_autolavado.id_mec";


 // connexion à la base de données
 try { 
 $bdd = new PDO("mysql:host=".$servidor."; dbname=".$bd."; charset=utf8", $usuario, $pass);
 } catch(Exception $e) {
 exit('No se Pudo Conectar.');
 }
 // exécution de la requête
 $resultat = $bdd->query($requete) or die(print_r($bdd->errorInfo()));
 $risultato = $bdd->query($querreque) or die(print_r($bdd->errorInfo()));

$resulteichon = $risultato.$resultat;
 //print_r($resultat->fetchAll(PDO::FETCH_ASSOC));
 // envoi du résultat au success
 echo json_encode($resulteichon->fetchAll(PDO::FETCH_ASSOC));

?>
    
asked by Sergio 20.01.2017 в 17:24
source

2 answers

1

The line

$resulteichon = $risultato.$resultat;

Must be replaced by

$resulteichon = print_r($risultato, true).print_r($resultat, true);

What the print_r() function does is to convert a PHP object to a string (character string) that can be concatenated. The value true in the second argument is for the function to return the string instead of printing it in the console.

    
answered by 07.11.2017 в 19:33
0

The error comes from this line:

$resulteichon = $risultato.$resultat;

The variables $risultato and $resultat are objects of the class PDOStatement and you can not concatenate them as if they were string .

    
answered by 20.01.2017 в 17:48