is this procedural or object oriented

I know that the php will stop support for mysql connection
but I want to know if this code I am using is procedural mysql connection or object oriented mysql connection

            $fetch = mysql_query("
SELECT * from email_doc where unix_timestamp>'1354308240' order by unix_timestamp
        ");    
  while ( $row = mysql_fetch_object( $fetch ) ) {
  echo $row->real_id;
}

Open in new window

LVL 1
rgb192Asked:
Who is Participating?
 
Olaf DoschkeSoftware DeveloperCommented:
The short answer: Your code will not work in PHP 5.5.0 and later, you have to change it. But that is not, because it is procedural programming style.

The original MySQL extension of PHP is just a set of functions. And this set of functions simply is removed from PHP since 5.5.0

Other  PHP functions are still part of the language and of course you can use them within any code, no matter if procedural or class code. So if you program procedural or OOP doesn't matter.

What matters is, you are forced to use either mysqli or PDO, if you use PHP 5.5 or later.

The nice thing about mysqli is, you can use it both ways in procedural style or oop style, as described here: http://www.php.net/manual/en/mysqli.quickstart.dual-interface.php
And in procedural style the calls mostly differ from the old mysql-function by the additional i in mysqli and secondary, the new parameter called "link".

If you really want to benefit from OOP programming, then redo everything from scratch, don't just make the minor step to use mysqli methods in the procedural style. But if time is of the essence, you have the chance to move to mysqli via that procedural style, because of how similar the usage is.

Bye, Olaf.
0
 
Loganathan NatarajanLAMP DeveloperCommented:
If you post the complete code, we may analyze and tell you.

What you've written is just piece of code from the db execution ... it is just written like mysql functions used etc.,

We cannot say with this code.
0
 
rgb192Author Commented:
this is the connection added
/* Connect to the database and select database */
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die(mysql_error());
mysql_select_db($dbname);

            $fetch = mysql_query("
SELECT * from email_doc where unix_timestamp>'1354308240' order by unix_timestamp
        ");    
  while ( $row = mysql_fetch_object( $fetch ) ) {
  echo $row->real_id;
}

Open in new window

0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
Loganathan NatarajanLAMP DeveloperCommented:
Its  just  procedural way of writing. If it has to be OOP's  then to be written in a common class and call the methods etc.,
0
 
Olaf DoschkeSoftware DeveloperCommented:
To clarify, see here for example:
http://www.php.net/manual/en/mysqli.query.php

mysqli is a base class of PHP and using it is object oriented.
There is both an object oriented syntax for usage and a procedural, but both use a mysqli class instance.

This means you just need a slight modification of procedural code from mysql_... to mysqli_... and already stop using the deprecated mysql_query() (and other mysql module functions). This gives you a way to reuse much code with just slight modifications.

If you want to go the full way then you'd change to mysqli or PDO_MySQL and use oop code syntax, too.

So in short:
The deprecation of mysql_query (and other mysql-functions) does not deprecate procedural programming style or syntax, as you can use the sister functions mysqli_...

OOP programming style is to be prefered, and you'd start by inheriting mysqli base class to your own needs data access class.

And last not least important: mysql_fetch_object() does not make PHP work object orientated, the results are only fetched in the form of simple record objects, with table fields as their properties/fields, but those objects are not instanciated classes with methods, events, etc.

Depending on how many code you have it's easier to migrate to mysqli, because of the procedural syntax you can continue to use, but I'd only make that decision, if the amount of code to rewrite would be a big issue.

See if mysqli or PDO make more sense in your case, by starting here:
http://www.php.net/manual/en/mysqlinfo.api.choosing.php

Bye, Olaf.
0
 
rgb192Author Commented:
>> then to be written in a common class and call the methods etc.,
does mysql class do this


>>mysqli
so mysql is not oo
0
 
rgb192Author Commented:
most complete explanation, thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.