colap Posted November 3, 2009 Share Posted November 3, 2009 <?php session_start(); mysql_connect("localhost","root","")or die('Could not connect: ' . mysql_error()); mysql_select_db("m"); $var=$_POST['ur']; $var2=$_POST['p']; $q="select * from table where col1='$var'"; $result=mysql_query($q) or die('Query error: '.mysql_error()); $c=mysql_num_rows($result); if($c==0) { echo "Wrong"; } else { echo "Success"; } ?> Is it possible to convert it to object oriented php? Quote Link to comment https://forums.phpfreaks.com/topic/180119-how-would-i-convert-it-to-object-oriented-php/ Share on other sites More sharing options...
Mchl Posted November 3, 2009 Share Posted November 3, 2009 Yes it is, but if you ask, you shouldn't do it. Quote Link to comment https://forums.phpfreaks.com/topic/180119-how-would-i-convert-it-to-object-oriented-php/#findComment-950204 Share on other sites More sharing options...
Daniel0 Posted November 3, 2009 Share Posted November 3, 2009 "Converting" to OOP usually requires a complete rewrite. You can't just go line for line and do like "then I'll replace X with Y" and eventually end up with OO code. Quote Link to comment https://forums.phpfreaks.com/topic/180119-how-would-i-convert-it-to-object-oriented-php/#findComment-950205 Share on other sites More sharing options...
Mchl Posted November 3, 2009 Share Posted November 3, 2009 "Converting" to OOP usually requires a complete rewrite. A complete rewrite of a whole application (or some major parts of it). 'Converting to OOP' this piece of code, without properly designing the rest of application is just an exercise in syntax. Quote Link to comment https://forums.phpfreaks.com/topic/180119-how-would-i-convert-it-to-object-oriented-php/#findComment-950210 Share on other sites More sharing options...
Daniel0 Posted November 3, 2009 Share Posted November 3, 2009 Hence the "usually" Quote Link to comment https://forums.phpfreaks.com/topic/180119-how-would-i-convert-it-to-object-oriented-php/#findComment-950214 Share on other sites More sharing options...
colap Posted November 3, 2009 Author Share Posted November 3, 2009 Searching i understand i have to create a Database.php file where there will be functions for conneting database,inserting,selecting,deleting,updating,disconnecting database etc. In the current .php file i would invoke the Database.php file creating object of Database.php file's class. Now my question is , "Is it possible to make it fully object oriented php"? That means from the current .php file, how would i call the functions of Database class? If i make a class from the current .php file, where would it start to execute php code from? As there is no main function or starting point in php file like C programming language of Java language. I have to make an object outside a class to call the functions of Database.php file's class.Am i right? If it's true , it's not possible to make it completely object oriented.Is it? Quote Link to comment https://forums.phpfreaks.com/topic/180119-how-would-i-convert-it-to-object-oriented-php/#findComment-950226 Share on other sites More sharing options...
mikesta707 Posted November 3, 2009 Share Posted November 3, 2009 why do you need a main function to use OOP? Python is OO but doesn't require a main function. In any programming language you have to create an instance of an object outside of the class definition. Having an object of the class inside the class doesn't really make any sense. When you include a class file in PHP, if all the code is inside the class definition, than no code is going to be run. (until you instantiate the class) by the way, there is nothing stopping you from making a main() function in PHP. Just make it somewhere on the page (or in the include) and call it in the page. Quote Link to comment https://forums.phpfreaks.com/topic/180119-how-would-i-convert-it-to-object-oriented-php/#findComment-950236 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.