Jump to content
Sign in to follow this  
vet911

Fatal error: Call to a member function query() on a non-object

Recommended Posts

I'm getting this error message after changing the $hostname given to me from Godaddy.

It lists line 68 as the error: this is the code section $result = $dbh->query($sql);

Any help would be appreciated.
	<?php
		try
		{
		  $type = $_GET['type'];
      //-query the database table
      if($_GET['type'] == 'ak')
				{
					//*$sql = "SELECT * FROM jewelry WHERE class = '$type' ";**/
          $sql = "SELECT id, cid, group, image_th, image, picture, comment FROM images  WHERE group = 'dionne' ORDER BY cid ASC";
				}
        else if($_GET['type'] == 'dionne')
				{
					$sql = "SELECT * FROM images WHERE picture = '2'";
				}
        
                 
			$result = $dbh->query($sql);

Share this post


Link to post
Share on other sites

Not sure what a hostname has to do with any of that code...

 

How about posting the rest of it? Be sure to include the bit where $dbh gets defined.

Share this post


Link to post
Share on other sites

I have included most of the code from the beginning.

<?php 
try
{
  {
		/*** mysql hostname ***/
		$hostname = 'xxxxxxxxxxxxxxxxxxxxx';

		/*** mysql username ***/
		$username = 'xxxxxxxxxx';

		/*** mysql password ***/
		$password = 'xxxxxxxxx';

		$dbname = 'xxxxxx';

		$dhb = null;

		$dbh = new PDO("mysql:host=$hostname;dbname=$dbname", $username, $password);
		$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
		$dbh->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true );

	/**	echo a message saying we have connected **/ 
	/**echo "connected"; **/
		
				
	}
	 
}
catch(PDOException $e)
{
	echo $e->getMessage();
}
?>
<div class="content">
<?php include('header.php');?>
<?php include('menu1.php');?>



		
 		<br />
 		<div>
		<center><table cellspacing="5" cellpadding="5" width="800" border="0">
    <tr>
    <td height="57" colspan="3" width="800">
    <hr />
    <div style="text-align: center;">Multiuse Pictures 2014</div>
    <div style="text-align: center;">Click picture to enlarge.</div>
    <hr />
    </td>
    </tr>
		<?php
		try
		{
		  $type = $_GET['type'];
      //-query the database table
      if($_GET['type'] == 'ak')
				{
					//*$sql = "SELECT * FROM jewelry WHERE class = '$type' ";**/
          $sql = "SELECT id, cid, group, image_th, image, picture, comment FROM images  WHERE group = 'dionne' ORDER BY cid ASC";
				}
        else if($_GET['type'] == 'dionne')
				{
					$sql = "SELECT * FROM images WHERE picture = '2'";
				}
        
                 
			$result = $dbh->query($sql);

			$rows2 = '0';
			$rows3 = '0';
		
			if($result)
			{
				$i = 0;
				$max_columns = 3;
				foreach ($result as $row)
				{
					// open row if counter is zero
					if($i == 0)
					{
						echo "<tr VALIGN='top'>";
					}
          // if ($row['avail'] != "0")
          //{
					// make sure we have a valid product ALIGN='CENTER'

					if($row['image_th'] != "" && $row['image_th'] != null)
					{

Share this post


Link to post
Share on other sites

You've got a try/catch up there at the top that will show an error message if PDO had a problem. Was there an error?

Share this post


Link to post
Share on other sites

Here is the error code:

 

Fatal error: Call to a member function query() on a non-object in <b>/home/content/r/i/g/rigtway/html/site_1.php on line 68

Share this post


Link to post
Share on other sites

Look at the top. Your database connection is failing with the credentials that you have used.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.