Database Code
  Home arrow Database Code arrow MySQL_Recordset
Codewalker Forums 
  Tutorials  
Database Articles  
Miscellaneous  
Navigation Usability  
PEAR Articles  
Programming Basics  
Server Administration  
XML Tutorials  
  Reviews  
Database Book Reviews  
Linux Book Reviews  
Miscellaneous Reviews  
PHP Book Reviews  
PHP Software Reviews  
Server Admin Reviews  
SQL Tool Reviews  
  Code Gallery  
Content Management Code  
Contest Code  
Counters Code  
Database Code  
Date Time Code  
Discussion Board Code  
Email Code  
File Manipulation Code  
GUI Code  
Link Farm Code  
Miscellaneous Code  
Search Code  
Site Navigation Code  
User Management Code  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Download TestComplete 
Forums Sitemap 
Weekly Newsletter 
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
DATABASE CODE

MySQL_Recordset
By: Codewalkers
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2002-06-27

    Table of Contents:

    Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    One Class out of three that conform an ADODB like object system to work with MySQL. Recordset provides access to data through sql execution.

    By : Slainte

    <?
    // Base recordset class for MySQL operations
    // Full information at http://www.phpclasses.org/mysql_db
    class mysql_recordset {

    // Init variables required

    VAR $connobj = "" ;
    VAR $sqlstring = "" ;

    // Data related variables

    VAR $rs = 0 ;
    VAR $row = 0 ;
    VAR $recordcount = 0 ;
    VAR $EOF = true ;

    // Private methods

    function get_recordset()
    {
    if ($GLOBALS[$this->connobj]->db && $this->sqlstring!="")
    {
    $this->rs = mysql_query($this->sqlstring,$GLOBALS[$this->connobj]->db) ;
    $GLOBALS[$this->connobj]->error_level = mysql_errno() ;
    $GLOBALS[$this->connobj]->error_desc = mysql_error() ;
    if ($this->rs)
    {
    $this->EOF = false ;
    $this->recordcount = mysql_num_rows($this->rs) ;
    $GLOBALS[$this->connobj]->msg = "\r\n" . date("d/m/Y - H:i:s") . " - OPERATION O.K.: Executed " . $this->sqlstring ." got " . $this->recordcount . " rows" ;
    } else {
    $this->recordcount = 0 ;
    $this->EOF = true ;
    $GLOBALS[$this->connobj]->msg = "\r\n" . date("d/m/Y - H:i:s") . " - OPERATION FAILED: Executed " . $this->sqlstring . " got " . $GLOBALS[$this->connobj]->error_level . " " . $GLOBALS[$this->connobj]->error_desc ;
    }
    } else {
    $this->recordcount = 0 ;
    $this->EOF = true ;
    $GLOBALS[$this->connobj]->msg = "\r\n" . date("d/m/Y - H:i:s") . " - OPERATION FAILED: No database open OR no SQL command provided" ;
    }
    $GLOBALS[$this->connobj]->debug() ;
    }

    function get_row()
    {
    if ($this->rs && $GLOBALS[$this->connobj]->db)
    {
    $this->row = mysql_fetch_array($this->rs) ;
    $GLOBALS[$this->connobj]->error_level = mysql_errno() ;
    $GLOBALS[$this->connobj]->error_desc = mysql_error() ;
    // $GLOBALS[$this->connobj]->msg = "\r\n" . date("d/m/Y - H:i:s") . " - OPERATION Executed got " . $GLOBALS[$this->connobj]->error_level . " " . $GLOBALS[$this->connobj]->error_desc ;
    // $GLOBALS[$this->connobj]->debug() ;
    if ($this->row)
    {
    $this->EOF = false ;
    } else {
    $this->EOF = true ;
    }
    } else {
    $GLOBALS[$this->connobj]->msg = "\r\n" . date("d/m/Y - H:i:s") . " - OPERATION FAILED: No database open" ;
    }
    }

    // Public interface

    function query()
    {
    $this->get_recordset() ;
    return $this->recordcount ;
    }

    function movenext()
    {
    $this->get_row() ;
    return $this->EOF ;
    }

    function field($campo)
    {
    echo $this->row[$campo] ;
    }

    function value($campo)
    {
    return $this->row[$campo] ;
    }

    function mysql_recordset($connobjname,$sqlcommand)
    {
    $this->connobj = $connobjname ;
    $this->sqlstring = $sqlcommand ;
    }

    function clear_recordset()
    {
    $this->sqlstring="" ;
    mysql_free_result($this->rs) ;
    }

    function move_to($rnumber)
    {
    if ($this->rs)
    {
    if (!mysql_data_seek($this->rs,$rnumber))
    {
    $GLOBALS[$this->connobj]->error_level = mysql_errno() ;
    $GLOBALS[$this->connobj]->error_desc = mysql_error() ;
    $GLOBALS[$this->connobj]->msg = "\r\n" . date("d/m/Y - H:i:s") . " - OPERATION FAILED: Could not move to record " . $rnumber . " " . $GLOBALS[$this->connobj]->error_level . " " . $GLOBALS[$this->connobj]->error_desc ;
    } else {
    $GLOBALS[$this->connobj]->msg = "\r\n" . date("d/m/Y - H:i:s") . " - OPERATION O.K.: Result pointer moved to " . $rnumber ;
    }
    } else {
    $GLOBALS[$this->connobj]->msg = "\r\n" . date("d/m/Y - H:i:s") . " - OPERATION FAILED: No result open" ;
    }
    $GLOBALS[$this->connobj]->debug() ;
    }

    function movefirst()
    {
    $this->move_to(0) ;
    }

    function movelast()
    {
    $this->move_to($this->recordcount-1) ;
    }
    }
    ?>
    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

    More Database Code Articles
    More By Codewalkers

     

    IBM® developerWorks developerWorks - FREE Tools!


    IBM DB2 Deep Compression ROI Tool

    The IBM DB2 Deep Compression ROI tool is designed for DBA’s and IT management personnel to perform a clinical analysis of the cost savings gained from the Storage Optimization feature of DB2 9 for Linux, UNIX and Windows. The feature, also known as Deep Compression, compresses data that lies within a database by up to 80% at times.
    FREE! Go There Now!


    NEW! Applying lean thinking to the governance of software development

    Effective governance for lean development isn’t about command and control. Instead, the focus is on enabling the right behaviors and practices through collaborative and supportive techniques. Hear from Scott Ambler on how it is far more effective to motivate people to do the right thing than it is to force them to do so. Learn how to form a lightweight, collaboration-based framework that reflects the realities of modern IT organizations.
    FREE! Go There Now!


    NEW! Download the free Web Application Security eKit

    Discover how IBM Rational AppScan Standard Edition can help you detext vulnerabilities in your web applications in the Web Application Security eKit. IBM Rational AppScan is a leading suite of automated web application security solutions that scan and test for common Web application vulnerabilities. The new Web Application Security eKit provides you with valuable resources, including white papers, demos, and additional information on the benefits of testing your Web applications.
    FREE! Go There Now!


    NEW! Evaluate IBM Rational Software Analyzer V7.0

    Download a free trial version of IBM Rational Software Analyzer Developer Edition V7.0 to identify bug defects earlier in the software development cycle. Rational Software Analyzer is an extensible software development solution that reduces the expense of bug-fixes by enabling static analysis code reviews and bug identification very early in the development cycle.
    FREE! Go There Now!


    NEW! Hello World: Monitor a simple business process using WebSphere Business Monitor V6.0.2

    This tutorial shows new users of IBM WebSphere Business Monitor Version 6.0.2 how to perform the "Hello World" equivalent for monitoring business process applications. It is intended to help you get familiar with the capabilities of the product.
    FREE! Go There Now!


    NEW! IBM Rational ClearCase Innovator's Series

    Learn from the best! Find out how developers use Rational ClearCase to be more flexible, innovative and deliver higher quality code in the Rational ClearCase Power Users eKit. This complimentary eKit provides a collection of materials, like articles, whitepapers, and demos that can help you become a power user of Rational ClearCase.
    FREE! Go There Now!


    NEW! Rational Build Forge Express eKit

    Rational Build Forge Express Edition is an automation framework that packages the latest enterprise-grade technologies into a reliable, flexible and robust configuration designed and priced specifically for small to midsize businesses. The new Rational Build Forge Express eKit provides you with valuable resources – including a case study, podcast, demo, and articles – to help you increase staff productivity, compress development cycles and deliver better software, fast.
    FREE! Go There Now!


    NEW! Try the IBM SOA Sandbox for Connectivity

    Visit IBM developerWorks to try the IBM SOA Sandbox for connectivity. The SOA Sandbox for connectivity provides a trial environment with the tooling and components to help you explore how to effectively connect your infrastructure and integrate all of the people, processes and information in your company. Use the hosted sandbox to explore SOA techniques that streamline connecting existing IT assets together, as well as learn how to connect them to new business logic.
    FREE! Go There Now!


    NEW! Webcast: Accelerating Software Innovation with System z

    Attend this launch webcast with Scott Hebner, Vice President of IBM Rational Marketing and Strategy, where he will overview Rational’s new offerings and programs to help customers accelerate software innovation on System z. He will discuss how these solutions help organizations extend their core business processes toward modern architectures such as SOA and web technologies to deliver business improvements that stand the test of time.
    FREE! Go There Now!


    NEW! Webcast: Quickly provide customized, integrated user interfaces with Lotus Notes 8

    IBM Lotus Notes 8 provides a wide range of developers the ability to provide customized, integrated user interfaces via composite applications and via custom sidebar and toolbar plug-ins. This webcast provides you with tips and techniques to use with out-of-the-box capabilities of Lotus Notes 8, and survey how you can share useful components within your own company and within a larger community.
    FREE! Go There Now!



    All FREE IBM® developerWorks Tools!

    DATABASE CODE ARTICLES

    - Examples and Tools for Database Design
    - Relationships, Entities and Database Design
    - Modeling and Designing Databases
    - Data extract to Excel
    - Oracle database class 0.76
    - The opposite of mysql_fetch_assoc
    - On line Thermal Transmitance Calculation
    - pjjTextBase
    - PHP Object Generator
    - FastMySQL
    - RC4PHP
    - SQL function with integrated sprintf()
    - DB Interaction Classes v1.1
    - deeMySQLParser
    - CSV to SQL convertor





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 3 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek