Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 06-12-2006, 10:44 AM   PM User | #1
fogofogo
New Coder

 
Join Date: Sep 2005
Posts: 89
Thanks: 2
Thanked 0 Times in 0 Posts
fogofogo is an unknown quantity at this point
connection error (mysqli)

Hello All,

I have a script that connects to a database and displays a few images and text. It worked fine when running on my machine at home, but I brought the code and database to another machine, and got a few errors. I'm pretty sure its to do with how my php.ini file is set up but I can seem to figure it out.

Heres the error message I get

Quote:
Warning: mysqli::mysqli() [function.mysqli]: (/1045): in C:\wamp\www\work\greg\db_fns.php on line 5

Warning: mysqli::query() [function.query]: Couldn't fetch mysqli in C:\wamp\www\work\greg\index.php on line 9

Fatal error: Call to a member function fetch_assoc() on a non-object in C:\wamp\www\work\greg\index.php on line 13
and heres the code for db_fns.php

PHP Code:
<?php

function db_connect()
{
   
$handle = new mysqli('localhost''content''password''content'); 
   if (!
$handle)
   {
     return 
false;
   }
   return 
$handle;
}

function 
get_writer_record($username)
{
  
$handle db_connect();
  
$query "select * from writers where username = '$username'";
  
$result $handle->query($query);
  return(
$result->fetch_assoc());
}

function 
get_story_record($story)
{
  
$handle db_connect();
  
$query "select * from stories where id = '$story'";
  
$result $handle->query($query);
  return(
$result->fetch_assoc());
}

function 
query_select($name$query$default='')
{
  
$handle db_connect();

  
$result $handle->query($query);

  if (!
$result)
  {
    return(
'');
  }

  
$select  "<select name='$name'>";
  
$select .= '<option value=""';
  if(
$default == ''$select .= ' selected ';
  
$select .= '>-- Choose --</option>';

  for (
$i=0$i $result->num_rows$i++) 
  {
    
$option $result->fetch_array();
    
$select .= "<option value='{$option[0]}'";
    if (
$option[0] == $default
    {
      
$select .= ' selected';
    }
    
$select .=  ">[{$option[0]}] {$option[1]}</option>";
  }
  
$select .= "</select>\n";

  return(
$select);
}

?>
and here is the code for index.php

PHP Code:
<?php
  
include_once('db_fns.php');
  
//include_once('header.php');

  
$handle db_connect();

  
$pages_sql 'select * from pages order by code';
  
$pages_result $handle->query($pages_sql);

  echo 
'<table border="0" width="400">';
      
  while (
$pages $pages_result->fetch_assoc()) 
  {
    
$story_sql "select * from stories
                  where page = '{$pages['code']}'
                  and published is not null
                  order by published desc"
;
   
    
$story_result $handle->query($story_sql);
    
    if (
$story_result->num_rows
    {
      
$story $story_result->fetch_assoc();
      echo 
"<tr>
            <td>
              <h2>{$pages['description']}</h2>
              <p>{$story['headline']}</p>
              <p align='right' class='morelink'>
                <a href='page.php?page={$pages['code']}'>
                Read more {$pages['code']} ...
                </a>
              </p>
            </td>
            <td width='100'>"
;
      if (
$story['picture'])
      {
        echo 
'<img src="resize_image.php?image=';
        echo 
urlencode($story[picture]);
        echo 
'&max_width=80&max_height=60"  />';
      }
      echo 
'</td></tr>';
    }
  }
  echo 
'</table>';

  
//include_once('footer.php');
?>
I've searched around but can't seem to figure it out. Any thoughts?

Thanks all
fogofogo is offline   Reply With Quote
Old 07-08-2006, 07:15 PM   PM User | #2
dswimboy
Regular Coder

 
dswimboy's Avatar
 
Join Date: Nov 2003
Location: mostly in Ann Arbor
Posts: 458
Thanks: 0
Thanked 0 Times in 0 Posts
dswimboy is an unknown quantity at this point
mysqli appears to require MySQL v4.1 or above. does your new machine have that?
__________________
"There is more than one way to do it."
dswimboy is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:03 PM.


Advertisement
Log in to turn off these ads.