Reputation: 1137
I'm very new to JQuery, but I was told the one of the cool things about it is you can query a mysql database right from an html page(or in my case a smarty template)with out needing php.
I have not found any examples of this so I am asking if someone has one? Thanks
Upvotes: 6
Views: 22589
Reputation: 382656
jQuery works client-side, you need a server-side language such as php, asp.net, etc to do that. Simply not possible with jQuery.
Upvotes: 2
Reputation: 9685
It is theoretically possible. You could write a simple MySql remote client in JS, and grant anonymous remote read-only access to certain parts of your database (like the content table, but not tables storing user data). It would be silly, but MySql does have direct remote access functionality. jQuery does not do this though, and trying it out would be a very silly idea, though it could be made sufficiently secure if you really wanted it.
Upvotes: 2
Reputation: 20493
Maybe you are referring to the client-side database API which is specified by HTML5.
Upvotes: 0
Reputation: 28160
Even if that was possible (it is not), it would be a horrible idea, as the visitor can see and manipulate everything that happens in javascript, so he would get free access to your database.
Some non-relational databases allow JSON queries, though.
Upvotes: 3
Reputation: 179994
Some sort of server-side interaction needs to be present.
Smarty's just a template language on top of PHP, so it's entirely possible to create a Smarty template that provides JavaScript-readable data (presumably, JSON or XML) for subsequent AJAX fetching via jQuery.
Upvotes: 0
Reputation: 120400
Let's hope that you continue not to find any examples of this. By necessity, DB access is kept away from the client. Imagine the mayhem if users could pop open your JS and start firing arbitrary queries/commands at your DB.
Upvotes: 20
Reputation: 17977
You can't do that. To use a database, there needs to be something on the server that connects to the DB server and authenticates.
PHP isn't necessarily needed. You could use Rails, Python, Java...
Upvotes: 1
Reputation: 449395
Nope, you're misinformed. This is definitely not possible. You will always need a server-side language to access a remote database, JQuery is not built to do this.
JQuery is able to parse RSS feeds, JSON and XML documents without a server-side language (related questions e.g. here and here). Maybe that is what you mean?
Upvotes: 6
Reputation: 887285
This is not possible.
You might be hearing about the HTML5 Web SQL Database standard.
Upvotes: 9