Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello all!

I was wondering if it would be possible to query a MySQL database using jQuery (or even standard Javascript). I am currently achieving this goal by using a XMLHttpRequest, and some PHP code.

JavaScript
function getCount() {
        var xmlhttp = new XMLHttpRequest();
        xmlhttp.onreadystatechange = function () {
            if (xmlhttp.readystate == 4 && xmlhttp.status == 200) {
                alert(xmlhttp.responseText);
                return xmlhttp.responseText;
            } else {
                alert(xmlhttp.responseText);
                return xmlhttp.responseText;
            }
        }

        xmlhttp.open("GET", "scripts/php/get.php?v=myval", true);
        xmlhttp.send();
    }


This works fine, but, my goal is to stop relying on PHP so much (don't get me wrong, I love PHP, I spend hours on end developing things with it everyday).

What I want to be able to do, is query my data, and store it as an array in Javascript, and then be able to work with the data using jQuery... If I still have to use PHP, that's fine, but I would prefer not having to use any echo calls.

Any help is appreciated,

Gigabyte Giant
Posted
Comments
Maciej Los 9-Oct-14 17:20pm    
Why don't you try to write ASP.NET site?
Gigabyte Giant 9-Oct-14 17:32pm    
I'm not a huge fan of ASP.NET. I used to spend a lot of time developing ASP.NET sites, but that was quite a few years back. Nowadays I prefer using languages such as PHP and JS.
Maciej Los 9-Oct-14 17:42pm    
OK. I'm interesting your reasons... PHP vs. ASP.NET[^]
Gigabyte Giant 9-Oct-14 17:48pm    
Well, I've just grown more fond of PHP. Don't get me wrong, ASP.NET is a great language, and I used to love working with it... I would use it for this project, however once I get a working prototype, I am submitting everything I make to a client, and they won't run ASP.NET at all...
Maciej Los 9-Oct-14 17:52pm    
Cool. I was curious ;)
Cheers,
Maciej

1 solution

Please, read my comment.

I'm not familiar with jQuery as good as i whish, but please, check this:
http://stackoverflow.com/questions/8598659/how-can-i-use-jquery-to-run-mysql-queries[^]
http://stackoverflow.com/questions/3020751/can-javascript-connect-with-mysql[^]
http://dev.mysql.com/doc/ndbapi/en/ndb-nodejs-setup.html[^]

As i mentioned (in the comment), i suggest to write ASP.NET + MySQL Connector[^].
 
Share this answer
 
Comments
Gigabyte Giant 9-Oct-14 17:34pm    
...read (and responded to) your comment. I will take a look at those links, however I doubt I will do anymore ASP.NET development anytime soon. Will mark as answer if the links help me. :)
Maciej Los 9-Oct-14 17:45pm    
I'll be glad, if my answer will be helpful. Take your time ;)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900