954,587 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

php/mysql query question

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?

RazorRamon
Junior Poster in Training
74 posts since Sep 2010
Reputation Points: 10
Solved Threads: 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...

P0lT10n
Posting Whiz in Training
235 posts since Apr 2010
Reputation Points: 13
Solved Threads: 30
 

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.

broj1
Posting Whiz
359 posts since Jan 2011
Reputation Points: 29
Solved Threads: 43
 

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.

RazorRamon
Junior Poster in Training
74 posts since Sep 2010
Reputation Points: 10
Solved Threads: 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.

jkon
Posting Whiz in Training
281 posts since Jan 2009
Reputation Points: 77
Solved Threads: 47
 

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

RazorRamon
Junior Poster in Training
74 posts since Sep 2010
Reputation Points: 10
Solved Threads: 0
 

Mark this thread as solved please !

P0lT10n
Posting Whiz in Training
235 posts since Apr 2010
Reputation Points: 13
Solved Threads: 30
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: