Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8500207
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T00:52:59+00:00 2026-06-11T00:52:59+00:00

I tried following this tutorial on PDOs, followed it exactly, yet when trying to

  • 0

I tried following this tutorial on PDOs, followed it exactly, yet when trying to connect on a very basic level, it’s outputing a non object error. I made a small test to determining the boolean of the $query variable and it’s coming out as false which is generating the error. Why is it doing this?:

TUTORIAL

http://www.youtube.com/watch?v=lb0NYODtGr4&feature=share&list=EC23A4AFEA46A5CB23

ERROR

Fatal error: Call to a member function fetch() on a non-object in
C:\xampp\htdocs\projects\dentaloffice\php\php_connect.php on line 16

CODE

<?php

$config['db'] = array(
    'host'      => 'localhost',
    'username'  => 'root',
    'password'  => '',
    'dbname'    => 'dentaloffice'
);

$db = new PDO('mysql:host=' . $config['db']['host'] . ';dbname =' . $config['db']['dbname'], $config['db']['username'], $config['db']['password']);

$query = $db->query("SELECT appointments.ROOM FROM appointments");

if($query === false){
    echo '$query variable returned false <br>';
}else{
    echo '$query variable returned true <br>';
}

while ($row = $query->fetch(PDO::FETCH_ASSOC)){
    echo $row['ROOM'];
}

?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T00:53:01+00:00Added an answer on June 11, 2026 at 12:53 am

    Change this line:

    $db = new PDO('mysql:host=' . $config['db']['host'] . ';dbname =' . $config['db']['dbname'], $config['db']['username'], $config['db']['password']);
    

    … into this …

    $db = new PDO("mysql:host={$config['db']['host']};dbname={$config['db']['dbname']}",
                  $config['db']['username'], $config['db']['password']);
    

    In other words, remove the whitespace symbol right after dbname, and it will work. ) PDO DSN syntax is quite strict, and the string in your example is parsed like no database was specified – hence an error you see.

    BTW, it’s a good practice to always check errorInfo() in the way shown in my previous comment in false query/statement/result branches of the PDO code. And now you probably see why. )

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new trying to configure MQ service following this tutorial but when I tried
I'm trying to open a pop-up menu from a NSToolbarItem. I tried following this
I'm very new to Git and I've been following this online tutorial for converting
I tried following this http://net.tutsplus.com/tutorials/javascript-ajax/an-introduction-to-the-raphael-js-library/ tutorial, but it does not work exactly with Raphael
I tried to compile Speex library on iOS following this tutorial and succeeded to
I have been following this tutorial, http://ruby.railstutorial.org/chapters/modeling-users?version=3.2#top , and I tried this in the
I've been experimenting with ASP.NET MVC and following this tutorial to create the basic
I'm new to AndEngine and I'm trying to implement hanoi game following this tutorial
I tried to run HtmlUnit with Jython following this tutorial: http://blog.databigbang.com/web-scraping-ajax-and-javascript-sites/ but it does
I am following this tutorial . Although I did exactly same as the tutorial,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.