Database Code

  Home arrow Database Code arrow MySQL_Command
DATABASE CODE

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

    Table of Contents:

     
     

    SEARCH CODEWALKERS

    TOOLS YOU CAN USE

    advertisement
    One Class out of three that conform an ADODB like object system to work with MySQL. Command provides acces to SQL execution returning no rows like updates, deletes, etc.

    By : Slainte

    <?
    // Base SQL command class for MySQL operations
    // Full information at http://www.phpclasses.org/mysql_db
    class mysql_command {

    // Init variables required

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

    // Data related variables

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

    // Private methods

    function exec_command()
    {
    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 = true ;
    $this->recordcount = mysql_affected_rows() ;
    $this->lastid = mysql_insert_id() ;
    $GLOBALS[$this->connobj]->msg = "\r\n" . date("d/m/Y - H:i:s") . " - OPERATION O.K.: Executed " . $this->sqlstring ." affected " . $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 " . mysql_errno() . " " . mysql_error() ;
    }
    } 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() ;
    }

    // Public interface

    function execute()
    {
    $this->exec_command() ;
    return $this->recordcount ;
    }

    function mysql_command($connobjname,$sqlcommand)
    {
    $this->connobj = $connobjname ;
    $this->sqlstring = $sqlcommand ;
    }
    }
    ?>
    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

    blog comments powered by Disqus

    DATABASE CODE ARTICLES

    - Converting CSV Files to MySQL Insert Queries...
    - 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


    © 2003-2012 by Developer Shed. All rights reserved. DS Cluster 3 - Follow our Sitemap