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  
Forums Sitemap 
Dedicated Servers  
Download TestComplete 
JMSL Numerical Library 
IBM® developerWorks
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!


    NEW! "ebook: Exploring IBM SOA Technology & Practice

    Learn field-tested SOA principles, methodology, technology and implementation from the global SOA market leader - in a new e-book by an IBM SOA expert. Written by IBM Certified SOA Solution Designer Bobby Woolf, "Exploring IBM SOA Technology & Practice" is the ultimate insider's guide to SOA - a PDF e-book packed cover to cover with IBM's specific advice on how to make your SOA implementation a success.
    FREE! Go There Now!


    NEW! Addressing software-as-a-service challenges using Tivoli security and WebSphere solutions

    Building a software-as-a-service solution requires addressing a few key technical challenges. In this webcast, we'll focus on the role of IBM Tivoli Directory Server and WebSphere Portlet Factory in creating a Software as a Service solution. We will demonstrate how to use Tivoli Directory Server to prevent the user population of one tenant from accessing the virtual portal and portlet components of another tenant. We will also use the dynamic profile capability of WebSphere Portlet Factory to create multiple highly customized applications from one code base.
    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! Best Practices in Integrated Requirements Management

    Poor Requirements Management capabilities in an Enterprise have been linked to excessive project failures, escalating IT costs, and failure to deliver competitive advantage into the marketplace. Join Brianna M Smith from IBM Rational and learn about how successful organizations align IT and Business stakeholders through collaborative processes and tools for effective requirements management, and how an integrated approach across the IT lifecycle can provide unparalleled visibility and traceability to ensure that project teams are delivering on the business vision by "doing the right things" and "doing things right."
    FREE! Go There Now!


    NEW! Download a free trial of Lotus Quickr 8.0

    Visit IBM developerWorks to download a free trial version of Lotus Quickr 8.0, which enables collaboration by transforming the way everyday business content such as documents, rich media, photos, and video can be shared. Lotus Quickr makes it faster and easier to share content of all types (not just documents) within virtual teams. It is designed to make it easier to collaborate across organizational boundaries, while continuing to work within the context of familiar desktop applications.
    FREE! Go There Now!


    NEW! Download IBM WebSphere Portal V6.1 beta code

    Download the IBM WebSphere Portal V6.1 beta code and learn more about the rich features and enhancements in IBM WebSphere Portal V6.1. WebSphere Portal provides a composite application or business mashup framework and the advanced tooling needed to build flexible, SOA-based solutions, and scalability to meet the needs of any size organization.
    FREE! Go There Now!


    NEW! Evaluate IBM Lotus Sametime Standard V8.0

    Visit IBM developerWorks to download a free trial of the latest release of IBM Lotus Sametime Standard V8.0. Lotus Sametime Standard V8.0 is a platform for unified communications and collaboration that combines security features with an extensible, open solution including integrated Voice over IP, geographic location awareness, mobile clients, and a robust Business Partner community offering telephony and video integration.
    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: Calling All Testers! Find Application Vulnerabilities Early in the Development Process Where they are Easier to Fix and Less Risky to your Business

    In this webcast, IBM Rational will discuss the importance of Web application security and will share techniques and best practices to introduce application security testing into current QA processes including: understanding common security vulnerabilities and techniques to integrate security testing with defect tracking and remediation systems in an effort to safeguard sensitive online information.
    FREE! Go There Now!


    NEW! Webcast: Extreme transaction processing with WebSphere Extended Deployment

    In this webcast, you'll get an introduction to the eXtreme Transaction Processing (XTP) features of WebSphere Extended Deployment and the common architectural traits required by XTP applications. See how WebSphere Extended Deployment's ObjectGrid feature provides a state-of-the-art infrastructure for hosting XTP applications.
    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-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway