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?

Member Avatar for P0lT10n

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

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.

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.

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.

Thanks i'll def spend some time on learning that.

Member Avatar for P0lT10n

Mark this thread as solved please !

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.