Miek
Miek

Reputation: 1137

Accessing Mysql with JQuery without using php

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

Answers (9)

Sarfraz
Sarfraz

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

Nicholas Wilson
Nicholas Wilson

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

Andrea
Andrea

Reputation: 20493

Maybe you are referring to the client-side database API which is specified by HTML5.

Upvotes: 0

Tgr
Tgr

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

ceejayoz
ceejayoz

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

spender
spender

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

Amy B
Amy B

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

Pekka
Pekka

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

SLaks
SLaks

Reputation: 887285

This is not possible.

You might be hearing about the HTML5 Web SQL Database standard.

Upvotes: 9

Related Questions