Link to home
Start Free TrialLog in
Avatar of rgb192
rgb192Flag for United States of America

asked on

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

Avatar of Loganathan Natarajan
Loganathan Natarajan
Flag of India image

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.
Avatar of rgb192

ASKER

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

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.,
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.
Avatar of rgb192

ASKER

>> then to be written in a common class and call the methods etc.,
does mysql class do this


>>mysqli
so mysql is not oo
ASKER CERTIFIED SOLUTION
Avatar of Olaf Doschke
Olaf Doschke
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rgb192

ASKER

most complete explanation, thanks