6

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

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Miek
  • 1,127
  • 4
  • 20
  • 35
  • 10
    @downvoters: Just because the OP has been misinformed doesn't mean his question needs downvoting. – RichieHindle Apr 26 '10 at 20:02
  • 3
    This question is in fact deeply inspired and unique, He has come to SO after googling enough without finding sufficient answers. Unfortunately we could do is to comment, criticise and turned down by saying impossible, not-recommented, horrible blah blah...None of us dared to provide a least working example code snippet with word of cautions so that OP can decide further whether to continue or not. – nehem Aug 27 '15 at 05:14
  • Possible duplicate of [Is it possible to interact with a MySQL database without PHP](https://stackoverflow.com/questions/32402875/is-it-possible-to-interact-with-a-mysql-database-without-php) – Rafiqul Islam Sep 15 '17 at 04:20

9 Answers9

20

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.

spender
  • 117,338
  • 33
  • 229
  • 351
9

This is not possible.

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

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
6

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?

Community
  • 1
  • 1
Pekka
  • 442,112
  • 142
  • 972
  • 1,088
3

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.

Tgr
  • 27,442
  • 12
  • 81
  • 118
2

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.

Nicholas Wilson
  • 9,435
  • 1
  • 41
  • 80
2

jQuery works client-side, you need a server-side language such as php, asp.net, etc to do that. Simply not possible with jQuery.

Sarfraz
  • 377,238
  • 77
  • 533
  • 578
1

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

Amy B
  • 17,874
  • 12
  • 64
  • 83
0

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.

ceejayoz
  • 176,543
  • 40
  • 303
  • 368
0

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

Andrea
  • 20,253
  • 23
  • 114
  • 183