Retrieving and displaying data from MySql in PhP

Przemek Wojtas

I have ran into a problem that says:

Catchable fatal error: Object of class PDOStatement could not be converted to string in F:\University\xampp\htdocs\database.php on line 36

Connection to a database is successful it is just that I cannot retrieve a data from my database and display it on the page.

Here's my database:

http://screenshot.sh/m1Ol9a8Fp2j3a

And here is my code

    <?php
$conn = new PDO(
    'mysql:host=localhost;dbname=u1358595', 
    'root'
    );
try{
       $conn = new PDO('mysql:host=localhost;dbname=u1358595', 'root');
    echo "Connected successfully"; 
}

catch (PDOException $exception) 
{
    echo "Oh no, there was a problem" . $exception->getMessage();
}
$query = "SELECT * FROM hotel";
$results = $conn->query($query, PDO::FETCH_OBJ);
$hotel = $results->fetch();
echo "<p>".$results."</p>";
$conn=NULL;
?>
Fluinc

You are trying to echo a PDO Object which doesn't work. You are passing the data to $hotel and to show the data you will use hotel.

<?php
$conn = new PDO(
    'mysql:host=localhost;dbname=u1358595', 
    'root'
    );
try{
       $conn = new PDO('mysql:host=localhost;dbname=u1358595', 'root');
    echo "Connected successfully"; 
}

catch (PDOException $exception) 
{
    echo "Oh no, there was a problem" . $exception->getMessage();
}
$query = "SELECT * FROM hotel";
$results = $conn->query($query);
$hotel = $results->fetch();

echo '<pre>';
var_dump($hotel);
echo '</pre>';

$conn=NULL;
?>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

MVC Retrieving Data From DB and Displaying it in View

From Dev

Php and MySQL: retrieving data from a database based on the link a user clicks

From Dev

Fetching data from MySQL database using PHP, Displaying it in a form for editing

From Dev

Displaying an image in PHP from MYSQL?

From Dev

Retrieving data from MySQL database

From Dev

PHP file not retrieving data from my mySQL database server

From Dev

Displaying data from mysql into two bootstrap columns using php

From Dev

PHP Retrieving Data From MySQL After Modifying URL Parameter

From Dev

Xcode, PHP; Having trouble with retrieving data from PHP/MySQL with SwiftyJSON-master

From Dev

Retrieving and displaying data from Wordpress database

From Dev

PHP MYSQL Displaying the same data from table to another page

From Dev

Php and MySQL: retrieving data from a database based on the link a user clicks

From Dev

Retrieving Data from mysql

From Dev

Retrieving data from MySQL db

From Dev

PHP Echo not displaying data from MySql

From Dev

PHP select one data from mysql NOT DISPLAYING

From Dev

displaying data from MySQL in PHP according to a condition

From Dev

PHP Retrieving Data from MySQL Database Error

From Dev

Retrieving data from databse using the dropdown selected list in php and mysql

From Dev

Retrieving data from MySQL database

From Dev

Displaying data from mysql database

From Dev

Displaying data in table format from mysql database with php loop

From Dev

Displaying Products from Mysql PHP

From Dev

PHP file not retrieving data from my mySQL database server

From Dev

Retrieving data from a listview and displaying it in a textview/imageview

From Dev

Xcode, PHP; Having trouble with retrieving data from PHP/MySQL with SwiftyJSON-master

From Dev

PHP retrieving data from a database

From Dev

Displaying date from mysql in php

From Dev

Unexpected Output while retrieving Data from mongodb and displaying in a csv file?

Related Related

  1. 1

    MVC Retrieving Data From DB and Displaying it in View

  2. 2

    Php and MySQL: retrieving data from a database based on the link a user clicks

  3. 3

    Fetching data from MySQL database using PHP, Displaying it in a form for editing

  4. 4

    Displaying an image in PHP from MYSQL?

  5. 5

    Retrieving data from MySQL database

  6. 6

    PHP file not retrieving data from my mySQL database server

  7. 7

    Displaying data from mysql into two bootstrap columns using php

  8. 8

    PHP Retrieving Data From MySQL After Modifying URL Parameter

  9. 9

    Xcode, PHP; Having trouble with retrieving data from PHP/MySQL with SwiftyJSON-master

  10. 10

    Retrieving and displaying data from Wordpress database

  11. 11

    PHP MYSQL Displaying the same data from table to another page

  12. 12

    Php and MySQL: retrieving data from a database based on the link a user clicks

  13. 13

    Retrieving Data from mysql

  14. 14

    Retrieving data from MySQL db

  15. 15

    PHP Echo not displaying data from MySql

  16. 16

    PHP select one data from mysql NOT DISPLAYING

  17. 17

    displaying data from MySQL in PHP according to a condition

  18. 18

    PHP Retrieving Data from MySQL Database Error

  19. 19

    Retrieving data from databse using the dropdown selected list in php and mysql

  20. 20

    Retrieving data from MySQL database

  21. 21

    Displaying data from mysql database

  22. 22

    Displaying data in table format from mysql database with php loop

  23. 23

    Displaying Products from Mysql PHP

  24. 24

    PHP file not retrieving data from my mySQL database server

  25. 25

    Retrieving data from a listview and displaying it in a textview/imageview

  26. 26

    Xcode, PHP; Having trouble with retrieving data from PHP/MySQL with SwiftyJSON-master

  27. 27

    PHP retrieving data from a database

  28. 28

    Displaying date from mysql in php

  29. 29

    Unexpected Output while retrieving Data from mongodb and displaying in a csv file?

HotTag

Archive