Development Articles
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOtherDevelopment Articles

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old February 4th, 2004, 10:37 AM
Admin Admin is offline
Developer Shed
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jan 2004
Posts: 961 Admin User rank is Sergeant Major (2000 - 5000 Reputation Level)Admin User rank is Sergeant Major (2000 - 5000 Reputation Level)Admin User rank is Sergeant Major (2000 - 5000 Reputation Level)Admin User rank is Sergeant Major (2000 - 5000 Reputation Level)Admin User rank is Sergeant Major (2000 - 5000 Reputation Level)Admin User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Article Discussion: Dynamically Insert and Update values in a MySQL database using OOP

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.


Read the full article here: Dynamically Insert and Update values in a MySQL database using OOP

Reply With Quote
  #2  
Old February 4th, 2004, 10:43 AM
gnorb gnorb is offline
Banned
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: Davie, FL
Posts: 0 gnorb User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via AIM to gnorb
Arrow Support File:

Support File: MyDatabaseClass.zip
Attached Files
File Type: zip mydatabaseclass.zip (3.4 KB, 1438 views)

Reply With Quote
  #3  
Old February 4th, 2004, 10:57 AM
Jcaputo's Avatar
Jcaputo Jcaputo is offline
Kiss My Converse!
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: May 2003
Location: Davie, Florida
Posts: 1,520 Jcaputo User rank is Major (30000 - 40000 Reputation Level)Jcaputo User rank is Major (30000 - 40000 Reputation Level)Jcaputo User rank is Major (30000 - 40000 Reputation Level)Jcaputo User rank is Major (30000 - 40000 Reputation Level)Jcaputo User rank is Major (30000 - 40000 Reputation Level)Jcaputo User rank is Major (30000 - 40000 Reputation Level)Jcaputo User rank is Major (30000 - 40000 Reputation Level)Jcaputo User rank is Major (30000 - 40000 Reputation Level)Jcaputo User rank is Major (30000 - 40000 Reputation Level)Jcaputo User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 2 Weeks 1 Day 19 h 26 m 5 sec
Reputation Power: 344
Sammy - excellent article, nice job! Hope to read some more of your articles in the near future.

Reply With Quote
  #4  
Old February 4th, 2004, 11:52 AM
SammyK's Avatar
SammyK SammyK is offline
Happy Monkey
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Nov 2001
Location: UK (University of Kentucky)
Posts: 1,810 SammyK User rank is Sergeant Major (2000 - 5000 Reputation Level)SammyK User rank is Sergeant Major (2000 - 5000 Reputation Level)SammyK User rank is Sergeant Major (2000 - 5000 Reputation Level)SammyK User rank is Sergeant Major (2000 - 5000 Reputation Level)SammyK User rank is Sergeant Major (2000 - 5000 Reputation Level)SammyK User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 3 Days 23 h 9 m 31 sec
Reputation Power: 42
Thanks man. That was my first one. [blushes]
__________________

Reply With Quote
  #5  
Old February 10th, 2004, 10:04 PM
eyrie eyrie is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Location: Queensland, Australia
Posts: 2 eyrie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 42 m 2 sec
Reputation Power: 0
Interesting idea, but your treatment is somewhat amateurish.

A better way to handle SQL layer abstraction is to encapsulate your SQL handler in a separate class from your database abstraction layer.

For a slightly classier approach, check out the SQL abstraction layer in worlddo.com's source code. You can download the source code for free at:

URL

Reply With Quote
  #6  
Old February 11th, 2004, 08:36 AM
rvasquez rvasquez is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 1 rvasquez User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thumbs up Great Idea ...

Excellent start to encapsulate SQL processing in a app ... this article gave some more ideas to do this ...
Thanks for the sharing, keep the good work

Reply With Quote
  #7  
Old February 11th, 2004, 10:21 PM
merlin9876 merlin9876 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 7 merlin9876 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I haven't had time to check out the article in depth, so this may be a stupid question, but couldn't anyone use a remote form and insert/upadte/delete whatever they wanted from the DB? I'm concerned about security risks.

Reply With Quote
  #8  
Old February 13th, 2004, 06:47 PM
SammyK's Avatar
SammyK SammyK is offline
Happy Monkey
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Nov 2001
Location: UK (University of Kentucky)
Posts: 1,810 SammyK User rank is Sergeant Major (2000 - 5000 Reputation Level)SammyK User rank is Sergeant Major (2000 - 5000 Reputation Level)SammyK User rank is Sergeant Major (2000 - 5000 Reputation Level)SammyK User rank is Sergeant Major (2000 - 5000 Reputation Level)SammyK User rank is Sergeant Major (2000 - 5000 Reputation Level)SammyK User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 3 Days 23 h 9 m 31 sec
Reputation Power: 42
Quote:
Originally Posted by merlin9876
I haven't had time to check out the article in depth, so this may be a stupid question, but couldn't anyone use a remote form and insert/upadte/delete whatever they wanted from the DB? I'm concerned about security risks.

Yes, it's not impossible which is why validation is crucial. Something off the top of my head you can do is unset all $_POST variables that have the same name as any crucial flags/other things you don't want changed in your database. Sometimes, however this is not possible or practical. The class as written as is here on DevShed will take any post variable received from the user and blindly dump it into the database. This is fine in most, simple and common cases, but I don't recommend anyone use it for production purposes unless you do some MAJOR data validation.

Reply With Quote
  #9  
Old March 17th, 2004, 11:38 AM
tlush tlush is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2001
Location: Newport, Rhode Island, USA
Posts: 15 tlush User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Dropping Leading Zeroes

I've tried this procedure for updating a database, but I find that when a field with a leading zero is added or updated the leading "0" is lost.

It might be the trim function in database.class.php.

Thanks -- Tony

Reply With Quote
  #10  
Old March 31st, 2004, 02:58 PM
SammyK's Avatar
SammyK SammyK is offline
Happy Monkey
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Nov 2001
Location: UK (University of Kentucky)
Posts: 1,810 SammyK User rank is Sergeant Major (2000 - 5000 Reputation Level)SammyK User rank is Sergeant Major (2000 - 5000 Reputation Level)SammyK User rank is Sergeant Major (2000 - 5000 Reputation Level)SammyK User rank is Sergeant Major (2000 - 5000 Reputation Level)SammyK User rank is Sergeant Major (2000 - 5000 Reputation Level)SammyK User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 3 Days 23 h 9 m 31 sec
Reputation Power: 42
Quote:
Originally Posted by tlush
I've tried this procedure for updating a database, but I find that when a field with a leading zero is added or updated the leading "0" is lost.

It might be the trim function in database.class.php.

Thanks -- Tony

This is because on line 69 (in the AddToDB method,) it checks to see if the value is numeric. If it is, then it inserts the value without single quotes around it. You can remove this condition statement and have it insert everything with single quotes around it. Don't forget to change it on line 128 in the UpdateDB method was well.

Reply With Quote
  #11  
Old April 16th, 2004, 05:33 PM
wpcmmx wpcmmx is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 1 wpcmmx User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Something Even More Dynamically And Flexible

Hi everybody, (English is not my native lenguage)

I am new with all this internet stuff. I am a computer engineer, and I am main programer on C, Tcl, OpenGL, and Oracle.

I am self learning HTML, CSS, PHP, MySQL, Javascript, XML, XSLT and I have a question:

These scripts are nice "Dynamically Insert and Update values in a MySQL database using OOP" but it will be better to make a new markup lenguage with XML, where you can write your own forms as a code (Block of data and relations between its) without placing any visual control, and then with XSLT and Javascript (I think) dynamically build all the controls necesaries for showing the data, besides building dynamically the necesary SQLs to load, update, insert, delete or relate data from these controls.

Is there some thing like it for HTML???

I am Oracle developer (I use Oracle for my developments, do not work at Oracle Company) and now I am seen Oracle Developer Siute 9i and when you build a form with Forms Builder, you can save it like XML, and the lenguage is easy to understand if you know Forms Builder philosophy, but I yet do not know how to display it in a browser (Build the DTD is not so difficult, but displaying it is what seams diffcult).

Some ideas ???

Thanks to everybody.

Reply With Quote
  #12  
Old April 16th, 2004, 06:20 PM
Sorvoja Sorvoja is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Location: Oslo, Norway
Posts: 120 Sorvoja User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 36 m 48 sec
Reputation Power: 5
The idea is a good one.
__________________
SEO Blog

Reply With Quote
  #13  
Old April 30th, 2004, 02:36 PM
JeffBernier JeffBernier is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 1 JeffBernier User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question

I really enjoyed the article. But I have a question.

How would you go about handling encrypted data (like passwords or credit card numbers) with this routine.

Jeff

Reply With Quote
  #14  
Old June 4th, 2004, 05:49 PM
SammyK's Avatar
SammyK SammyK is offline
Happy Monkey
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Nov 2001
Location: UK (University of Kentucky)
Posts: 1,810 SammyK User rank is Sergeant Major (2000 - 5000 Reputation Level)SammyK User rank is Sergeant Major (2000 - 5000 Reputation Level)SammyK User rank is Sergeant Major (2000 - 5000 Reputation Level)SammyK User rank is Sergeant Major (2000 - 5000 Reputation Level)SammyK User rank is Sergeant Major (2000 - 5000 Reputation Level)SammyK User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 3 Days 23 h 9 m 31 sec
Reputation Power: 42
Just encrypt it before it gets to the AddToDB method.
PHP Code:
 $_POST['password'] = md5($_POST['password']); 

Reply With Quote
Reply

Viewing: Dev Shed ForumsOtherDevelopment Articles > Article Discussion: Dynamically Insert and Update values in a MySQL database using OOP


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