MySQL
  Home arrow MySQL arrow Dynamically Insert and Update Values In a MySQL Database Using OOP
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
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? 
MYSQL

Dynamically Insert and Update Values In a MySQL Database Using OOP
By: Sam 'SammyK' Powers
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 89
    2004-02-04


    Table of Contents:
  • Dynamically Insert and Update Values In a MySQL Database Using OOP
  • Essential Connection
  • Adam Up
  • If You POST It, It Will Go
  • Updateagenessly
  • UpdateDB in Action
  • You Wouldn't Have to Update It Had You Gotten It Right the First Time

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log 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


    Dynamically Insert and Update Values In a MySQL Database Using OOP
    ( Page 1 of 7 )

    Stop writing insert and update SQL statements and cut the time you spend writing simple SQL in half while focusing on the more complicated things. Leave it up to OOP to help you out. We will make a class that goes out and looks for the values for us and builds a SQL statement on the fly. All we have to do is make sure the column names in the database correspond with the field names in the HTML form. Believe me when I say it saves TONS of time. I never write applications that don't use it.

    Time Is of the Essence

    So you have a new project. It requires simple add, edit, and delete actions. Simple enough, but think of all the time you spend writing simple, time-consuming insert and update SQL statements, and praying to God that you didn't mess up the column sequence, forget a comma, or make some other silly type-o that you spend precious coding time looking for and correcting.

    Think of the following: in a 25 or 50 field form, you have 50 or 100 pieces of data to enter into the SQL statement:


    mysql_query("INSERT INTO myTBL (col1,col2,col3,…col30,col31) VALUES ('".$val1."', '".$val2."', '".$val3."', …'".$is_this_val30."', '".$please_be_val31."'");

    It's confusing, and it makes your code look and feel like crap. It gets even worse when you have to add or delete a field, then you have to go through the SQL again and find that one column amidst the sea of endless columns and then go find that darned variable in that myriad of weird names you made up. Argh! I can hear your frustrations now. Well there is a solution to our long-SQL-statement-woes. We will make a class that goes out and looks for the values for us and builds a SQL statement on the fly. All we have to do is make sure the column names in the database correspond with the field names in the HTML form. Believe me when I say it saves TONS of time. I never write applications that don't use it.

    Enough chit-chat, let's start coding.



     
     
    >>> More MySQL Articles          >>> More By Sam 'SammyK' Powers
     

       

    MYSQL ARTICLES

    - Null and Empty Strings
    - MySQL Server Tuning Tips and Tricks
    - MySQL Query Optimizations and Schema Design
    - MySQL Benchmarking Tools and Utilities
    - MySQL Benchmarking Concepts and Strategies
    - Take Some Load off MySQL with MemCached
    - MySQL Table Prefix Changer Tool in PHP
    - Using the SIGNAL Statement for Error Handling
    - Error Handling Examples
    - Error Handling
    - Completing a Search Engine with MySQL and PH...
    - Paginating Result Sets for a Search Engine B...
    - Building a Search Engine with MySQL and PHP 5
    - Using Boolean Operators for Full Text and Bo...
    - PHP, MySQL and the PEAR Database





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
    Stay green...Green IT