yaserloz Posted November 11, 2011 Share Posted November 11, 2011 hi i made this glass for insert query i need some input about it and if its valid and if there any idea to put on it post it please the function take array data and table name <?php class DatabaseActions{ function Add($DataArray,$TableName){ $text="'"; foreach($DataArray as $key => $val) $text .= $val."','"; $text = substr($text,0,-2); $query = "INSERT INTO $TableName VALUES ($text)"; return $query; } } $a= new DatabaseActions ; $array = array (1,"string","11-12-1009:2233","+++//4rrrr"); $tablename = "subject"; $output=$a->Add($array,$tablename); echo $output; ?> output INSERT INTO subject VALUES ('1','string','11-12-1009:2233','+++//4rrrr') Quote Link to comment https://forums.phpfreaks.com/topic/250924-can-i-use-this-class-for-insert-query/ Share on other sites More sharing options...
KevinM1 Posted November 11, 2011 Share Posted November 11, 2011 Not really OOP. OOP is more than just stuffing what would simply go in a function inside a class. Your best bet is to use an existing OO solution (MySQLi or PDO) and figure out a way to incorporate your specific needs with it. Quote Link to comment https://forums.phpfreaks.com/topic/250924-can-i-use-this-class-for-insert-query/#findComment-1287300 Share on other sites More sharing options...
yaserloz Posted November 11, 2011 Author Share Posted November 11, 2011 ok its not about the class itself but about its work is good to use or not ? Quote Link to comment https://forums.phpfreaks.com/topic/250924-can-i-use-this-class-for-insert-query/#findComment-1287307 Share on other sites More sharing options...
freaker87 Posted November 11, 2011 Share Posted November 11, 2011 yes its good check this link here http://net.tutsplus.com/tutorials/php/real-world-oop-with-php-and-mysql/ Quote Link to comment https://forums.phpfreaks.com/topic/250924-can-i-use-this-class-for-insert-query/#findComment-1287314 Share on other sites More sharing options...
KevinM1 Posted November 11, 2011 Share Posted November 11, 2011 yes its good check this link here http://net.tutsplus.com/tutorials/php/real-world-oop-with-php-and-mysql/ Not a fan of that tutorial because it claims to be a real world example, but has the following flaws: No error handling. In fact the author squelches errors by using the '@' symbol liberally through his code. A true real world example would have exception handling. No escaping of values or anything else to combat an injection attack. An incredibly egregious omission for a tutorial aimed at newbies. A complete lack of ability to handle complex queries. Unless you have an embarrassingly simple domain, chances are you'll want to JOIN tables at some point. It's just a bad tutorial all around. Looks like the author wanted to make something that mimics a generic ORM, but neglected to build any of the functionality that makes them worthwhile to use. Quote Link to comment https://forums.phpfreaks.com/topic/250924-can-i-use-this-class-for-insert-query/#findComment-1287323 Share on other sites More sharing options...
yaserloz Posted November 11, 2011 Author Share Posted November 11, 2011 yes its good check this link here http://net.tutsplus.com/tutorials/php/real-world-oop-with-php-and-mysql/ thanks dude @Nightslyr can i use it as a base then develope it more and close all lacks u point to or should i ignore it and start with freash idea ? i need to start somthing can Bear any change in the future even if its simple for starter Quote Link to comment https://forums.phpfreaks.com/topic/250924-can-i-use-this-class-for-insert-query/#findComment-1287348 Share on other sites More sharing options...
KevinM1 Posted November 11, 2011 Share Posted November 11, 2011 To be honest, I think you should start with basic OO methodology before trying to move further. Knowing the syntax of objects does nothing to prepare one to use them properly. Right now, I have the feeling that if you tried to adapt the code in the tutorial, you would just blindly slap on parts that relate to the particular problem you're trying to solve rather than something more universally useful. In short, you need to learn how to crawl before you can walk. You should get two books before progressing much further: PHP 5: Objects, Patterns, and Practice by Matt Zandstra [Link] Design Patterns: Elements of Reusable Object-Oriented Software by the Gang of Four [Link] Quote Link to comment https://forums.phpfreaks.com/topic/250924-can-i-use-this-class-for-insert-query/#findComment-1287450 Share on other sites More sharing options...
yaserloz Posted November 11, 2011 Author Share Posted November 11, 2011 thanks i will stop every thing and read more Quote Link to comment https://forums.phpfreaks.com/topic/250924-can-i-use-this-class-for-insert-query/#findComment-1287459 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.