Can I execute MySQL SQL statements in FireFox?

夙愿已清 提交于 2019-12-12 10:08:15

问题


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.


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/7238006/can-i-execute-mysql-sql-statements-in-firefox

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!