0

Can you all tell me the difference in these 2 codes? I'm trying to learn JQuery and ive seen this code below in the tutorials.

$DB->Query("Select * FROM time");

I'm use to coding queries like this.

$res = mysql_query("SELECT timestamp, name FROM time ORDER BY timestamp DESC");

Whats the difference in these 2 codes and can I use the 2nd code in JQuery?

Edited by RazorRamon: code brackets wrong

4
Contributors
6
Replies
8
Views
6 Years
Discussion Span
Last Post by P0lT10n
0

First of all, jQuery is a Javascript Plugin, not a PHP Plugin.

Second, the differences are, in $DB->Query("Select * FROM time"); is with Object Oriented Programming in PHP, and $res = mysql_query("SELECT timestamp, name FROM time ORDER BY timestamp DESC"); is the normal way to do it...

0

The difference between exmples is:

The former is using object oriented programming aproach. $DB is an object and Query() is a method of that object. The later is classical procedural approach where mysql_query() is a function. Both do similar task I guess. You in general decide wheter to use object oriented programming or procedural.

Just a note: your question is about PHP and executing SQL statement on MySql database. JQuery, as faras I know, is a Javascript library and hasn't got much to do with PHP and MySql.

0

Yea well i knew jquery was a javascript based language but the query is what really threw me for a loop. Figured the mysql query was more of a php type question.

Ok i'm fine with doing the 2nd piece of code then right to handle queries in PHP/Mysql for JQuery?? That little arrow after $DB is something I hadn't seen before.

0

Forget JQuery , has nothing to do with your examples. $DB in your example is an instance of a class (a data base handler class I guess). Object oriented programming has lot advantages, PHP has a very good class PDO , that will make your life easier and more secure if you spent a day or two learning it.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.