开发者

Can I execute MySQL SQL statements in FireFox?

There is a FireFox plugin called greasemonkey with which you can execute some piece of JavaScript code on the page you specified. I want to know whether there is a way that I can embed SQL statements (MySQL) in JavaScript. If so, I can extract the information I开发者_开发百科 need and save them to my MySQL database for later use. Is this possible?

Thanks.


Strictly speaking, you cannot execute MySQL statements in Firefox, although you can in Chrome for the moment.

In Firefox you can create and use IndexedDB databases -- a more supported browser-DB approach (that is actually in the HTML5 spec). This might be enough, depending on your ultimate goal.

For full, traditional, DB support, you will have to write a web interface...

  1. You can host such an interface on any machine using something like XAMPP. (Or use the language of your choice.)

  2. Send your data from the Greasemonkey script to the web-app, using GM_xmlhttpRequest, like so:

    var myData      = {strVar: 'Hiya!', intVar: 777, etc: 'et cetera'};
    var DataForDB   = JSON.stringify (myData);
    
    GM_xmlhttpRequest ( {
        method:     "POST",
        url:        "http://localhost/YourDir/LogMyData.php",
        data:       DataForDB,
        headers:    {"Content-Type": "application/json"}
    } )
    


  3. A PHP webpage would extract the data like so:

    $myData = json_decode($HTTP_RAW_POST_DATA);
    print_r ($myData);
    
  4. The web page then interacts with mySQL as you see fit, returning any desired values to the GM script.


No, the process must be done using a server-side language, such as PHP. Javascript is a client-side language.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜