SunQuest
 
           MySQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMySQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old May 4th, 2003, 07:24 PM
The Letter J The Letter J is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Posts: 4 The Letter J User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
mySQL Driver Problems

I've made a mysql driver that almost works... I've tested it on a page and it always gives me an error and doesn't work the way it should. I set up a test table with 6 entries, the test script should print the entires in 6 table rows - the script creates 6 table rows but it doesn't include the data, and the error returned is saying that it couldn't be fetched...

Here is the test script:
PHP Code:
<?php
$root_path 
'';
include(
$root_path 'includes/extension.inc');
include(
$root_path 'includes/global.' $ext);
// these includes include the driver and create the connection

$db->query("SELECT * FROM driver_test");

echo 
"<table>\n";
while(
$test $db->fetch())
{
    echo 
"<tr><td>$test['id']</td><td>$test['name']</td><td>$test['email']</td></tr>\n";
}
echo 
"</table>\n\n";

if(
$db->is_errors())
{
    
$db->show_errors();
}

?>


And here is the driver itself:

PHP Code:
class MysqlDriver {

    
// ##################################################  #####
    //# Variables
    // ##################################################  #####
    
var $info = array(
                        
'db_server'     => '',
                        
'db_user'       => '',
                        
'db_database'   => '',
                        
'db_persistent' => false
                     
);
    
    var 
$error           = array();

    var 
$connect_id      0;
    var 
$query           0;
    var 
$results         = array();
    var 
$query_count     0;

    


    
// ##################################################  #####
    //# Functions
    // ##################################################  #####
    
    /// Constructor
    
function MysqlDriver($db_server ''$db_user ''$db_pass''$db_database ''$db_persistent false)
    {
        if(!(
$db_server == '' || $db_user == '' || $db_pass == '' || $db_database == ''))
        {
            
$this->info['db_server']     = $db_server;
            
$this->info['db_user']       = $db_user;
            
$this->info['db_pass']       = $db_pass;
            
$this->info['db_database']   = $db_database;
            
$this->info['db_persistent'] = $db_persistent;
            return 
true;
        }

        else
        {
            
$this->error[] = 'Insuffient number of arguments supplied to MysqlDriver';
            return 
false;
        }
    }

    
//#------------------------------------------------------
    //# Connection
    //#------------------------------------------------------
    /// Connect
    
function connect()
    {
        if(
$this->info['persistent'])
        {
            
$this->connect_id = @mysql_pconnect($this->info['db_server'],
                                                
$this->info['db_user'],
                                                
$this->info['db_pass']);
        }

        else
        {
            
$this->connect_id = @mysql_connect($this->info['db_server'],
                                               
$this->info['db_user'],
                                               
$this->info['db_pass']);
        }

        if(!(
$this->connect_id))
        {
            
$this->error[] = 'Could not establish mysql connection.'.$this->get_mysql_error();
            return 
false;
        }

        elseif(!(
mysql_select_db($this->info['db_database'], $this->connect_id)))
        {
            
$this->error[] = 'Could not select mysql database.'.$this->get_mysql_error();
            return 
false;
        }

        else
        {
            return 
true;
        }
        
    }

    
/// Disconnect
    
function disconnect()
    {
        if(
$this->result)
        {
            @
mysql_free_result($this->result);
        }

        if(!
mysql_close($this->connect_id))
        {
            
$this->error[] = 'Could not close mysql connection.'.$this->get_mysql_error();
            return 
false;
        }

        else
        {
            return 
true;
        }
    }

    
//#------------------------------------------------------
    //# Queries
    //#------------------------------------------------------
    /// Set Query
    
function query($query 0)
    {
        if(!(
$query))
        {
            
$this->error[] = 'Insufficient number of arguments supplied to MysqlDriver query()';
            return 
false;
        }

        else
        {
            
$this->query = @mysql_query($query$this->connect_id);
            if(!(
$this->query))
            {
                
$this->error[] = 'Could not execute query.'.$this->get_mysql_error();
                return 
false;
            }

            else
            {
                return 
true;
            }
        }
    }

    
/// Fetch Results
    
function fetch()
    {
        
$this->results = @mysql_fetch_array($this->query);
        if(!(
$this->results))
        {
            
$this->error[] = 'Could not fetch array.'.$this->get_mysql_error();
            return 
false;
        }

        else
        {
            return 
$this->results;
        }
    }

    
/// Free Result
    
function free_result()
    {
        if(!(
mysql_free_result($this->query)))
        {
            return 
false;
        }

        else
        {
            return 
true;
        }
    }

    
/// Get Number of Rows
    
function get_num_rows()
    {
        return 
mysql_num_rows($this->query);
    }

    
/// Get Number of Affected Rows
    
function get_affected_rows()
    {
        return 
mysql_affected_rows($this->connect_id);
    }

    
/// Get Number of Queries Used
    
function get_query_count()
    {
        return 
$this->query_count;
    }




    
//#------------------------------------------------------
    //# Errors
    //#------------------------------------------------------
    /// Check for errors
    
function is_errors()
    {
        if(
count($this->error) >= 1)
        {
            return 
true;
        }

        else
        {
            return 
false;
        }
    }

    
/// Print out the errors
    
function show_errors()
    {
        if(
count($this->error) >= 1)
        {
            echo 
'<font face="Verdana" size="-1"><u>Warning: The following error(s) have occurred</u><br />';
            foreach(
$this->error as $value)
            {
                echo 
'<li>'.$value.'</li>';
            }
            echo 
'</font>';
        }
    }

    
/// Return Formatted mySQL Errors
    
function get_mysql_error()
    {
        
$string ' <small><b>('.@mysql_errno().': '.@mysql_error().')</b></small>';
        return 
$string;
    }




It seems to be a problem with the fetch, but I dont know...

Reply With Quote
  #2  
Old May 5th, 2003, 06:20 PM
mytch mytch is offline
Dev Articles Novice (500 - 999 posts)
 
Join Date: Apr 2002
Location: Sydney, Australia
Posts: 589 mytch User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Hi,
Try changing

PHP Code:
var $results         = array(); 


in the constructor to

PHP Code:
var $results         null


The result pointer returned by mysql_result isn't necessarily an array... so it might not be able to explicitly cast it to an array, this producing an error

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMySQL Development > mySQL Driver Problems


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway