Jump to content

Recommended Posts

<?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?

"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.

 

 

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?

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.