SharkBait Posted August 18, 2006 Share Posted August 18, 2006 Yes this has been hit around billions of times but this is my question..I use this bit of code lots:[code]<?php$strqry = "SELECT * FROM blah WHERE blah1 = blah2";$query = mysql_query($strqry) or die("MySQL Error: <br />{$strqry}<br />". mysql_error());$result = mysql_fetch_array($query, MYSQL_ASSOC);?>[/code]Now other things I might also do with my queries is like mysql_num_rows() or mysql_affected_rows, might Delete an entry or three or update a row etc.Would it be best to come up with my own class that I could use and manipulate the arguments. Like $strqry or something?I use classes with my VB.Net projects but I want to get into using them more with PHP. That and I think it will also allow me to clean up my code since alot of my sql queries are just repeated over and over and over. Why type if all out again?So.. my question(s):1) Is my logic with this correct?2) How hard is it to create a class I can use and learn from that will do the above3) How's the weather where you are?=-) I just want to get more into the OOP part of PHP like I did with VB.NET because it makes things soo much easier if they are repeative bits of coding I need to use.Thanks Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted August 19, 2006 Share Posted August 19, 2006 [quote]1) Is my logic with this correct?[/quote]Yes.[quote]2) How hard is it to create a class I can use and learn from that will do the above[/quote]Not very.[quote]3) How's the weather where you are?[/quote]Hot, and humid.I sometimes use a mysql abstraction class from this website: http://jaws.townsville.nl/, called ActiveRecord. Most of the time I will write my own, however, this one is pretty good in my opinion. If nothing else, you can use it as an example to learn something for your class.phpclasses.org also has about a million mysql classes that you can take a look at. Quote Link to comment Share on other sites More sharing options...
SharkBait Posted August 21, 2006 Author Share Posted August 21, 2006 I have this:[code]<?phpclass MySQL { var $rows; var $length; function doQuery($string) { $query = mysql_query($string) or die("MySQL Error: <br /> {$strqry}<br />". mysql_error()); $this->$rows = mysql_fetch_array($query, MYSQL_ASSOC); $this->$length = mysql_num_rows($query); }}// then to use it would I:$myQuery = &new MySQL;$strqry = "SELECT * FROM BLAH";$myRows = $myQuery->doQuery($strqry);if($myRows->length < 0) { // Nothing found} else { // Found something}?>[/code]Would that be the similar thing as[code]<?php$strqry = "SELECT * FROM Blah";$query = mysql_query($strqry) or die("MySQL Error: <br /> {$strqry} <br />". mysql_error());$result= mysql_fetch_array($query, MYSQL_ASSOC);$num = mysql_num_rows($query);if($num <0) { // Nothing returned} else { // Found something}?>[/code] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.