If possible, how can I get (and post) data from a mysql database using javascript? I know I can use php and other languages, but I just need to know if this is possible with javascript?
Thanks in advance.
That's not possible with Javascript. I could not find this with server-side javascript too.
Not sure about your exact requirement, but you can use Ajax to interact with database though some server side language.
If by Javascript you mean NodeJS on the server, this project might interest you http://github.com/sidorares/nodejs-mysql-native - however the answers above are correct if you are talking about Javascript running inside a browser or other container.
If you want to run a vanilla javascript (for the concurrency speed) inside your own engine, I recommend looking at NodeJS and then using the NodeJS MySQL Native Driver that I linked above.
• http://github.com/sidorares/nodejs-mysql-native
Judging from the "iPhone" and "Android" tags, I guess, you are trying to access the local storage databases on these platforms.
They don't use MySQL, but SQLite.
How you access them from the mobile browsers is described in the W3C draft documents for the local storage: http://dev.w3.org/html5/webstorage/ for the local storage API or http://www.whatwg.org/specs/web-apps/current-work/multipage/section-sql.html#sql for the SQL API. It should be roughly the same API on iOS and Android since both of them use the Webkit browser engine.
it is not possible, javascript is executed on the client.
you could make the javascript call something on the server (e.g. php script) that access the database though.
The Web SQL database API isn’t actually part of the HTML5 specification, but it is part of the suite of specifications that allows us developers to build fully fledged web applications, so it’s about time we dig in and check it out.
Some examples are here
http://html5doctor.com/introducing-web-sql-databases/
Do remove the tags iphone and android from this question. the tags are not relevant.
And only with javascript you cant accompolish this task , GET and POST request can be handled only by server side scripting languages like php.
Refer : http://www.javascriptkit.com/dhtmltutors/ajaxgetpost.shtml
javascript can get database from server
if use AJAX , only a way is AJAX
Related
I have a PHP script for my contact form, but my host is not compatible with PHP scripts. Is there a way to get this PHP code in an <script>tag?
No, there is not. PHP runs on the server, not on the client.
And this is for good reasons. A lot of the things you do with PHP, you wouldn't want to let the client do anyway. For instance loading data from the database - if you gave the client your database password it could get any data from your database.
Some of the things done with PHP could be done in JavaScript instead, but in quite different ways. But not all things could.
If your host does not support PHP, you will either have to live without it or change host.
If your server is not compatible with PHP how do you plan one running PHP? To answer your question, no.
However you could look into using node.js
check this out http://www.nodemailer.com/
No you can't, because PHP is a server-side language, so if your server doesn't support PHP you can't do anything: tags are for client-side languages, such as Javascript, so in this case are useless.
What languages does your server support?
No. If the PHP software itself isn't installed on the server, it isn't available to you to run from any scripts as it is server-side code and has nothing to do with the browser (client-side).
However, if PHP was installed on the server, you can run PHP code within <script> tags as follows:
<script language="php">
// Your PHP code
</script>
(But that isn't good practice)
It's not a good practice to use server side scripts on the front end, better use client side scripts, say javascript. Server side scripting should be used to serve and consume data, to clean user submitted data mainly.
Please make you a favor and enter javascript . There are many good modern frameworks like ANGULARJS and REACTJS, just to mention my preferred.
Having said that, I answer your question, no it's not possible, but your hosting should support any server, so better ask what server scripting does it provide, because it must. The majority of web hostings provide PHP as default.
As the question says, is it possible to interact with a MySQL database created with XAMPP (so, using PhpMyAdmin) without using PHP, but only Javascript/JQuery?
This is a merely theoretical question, I don't want to know how to (but if you know it, I want discard your help).
With this, I don't mean using Ajax to send my request to a .php page that will then interact with the database, but directly interacting without passing through PHP.
In terms of a PHP application, it's not possible to interact with MySQL through JavaScript because JavaScript is executed client side i.e in the browser, it doesn't have access to anything on the server it is being served from.
However, with nodejs - a JavaScript runtime built on Chrome's V8 JavaScript engine - you can write a complete JavaScript server side application without having to touch PHP. There's a node-mysql module which means you can interact with a MySQL database with JavaScript code.
Several web application frameworks exist to help you get something up and running like Express, which saves you the burden of having to write up things like routing logic.
No you can't interact with MySQL through JavaScript or JQuery. You could use JavaScript and JQuery through your PHP pages if that would be a functionality you'd be interested in. You could also use another language compatible with MySQL. Otherwise interacting with MySQL straight through JavaScript/JQuery won't work.
You can do openDatabase()
Make an SQL file, db.sql,
and in a javscript file, type this: openDatabase(db.sql, '1.0', 'My First Database', 65535)
More on this here: http://html5doctor.com/introducing-web-sql-databases/.
This makes an SQLite connection. I recommend it as it doesn't use PHP, but if you really really want to use MySQL(Again, I recommend using this SQLite method) you have to use PHP or some sort of server scripting language.
Learn SQLite: https://www.tutorialspoint.com/sqlite/index.htm
This works on:
XAMPP
repl.it
well, basically anything.
I've developed an application that I would like to use meteor.js for real time updates (I want to enhance but not change my program, for example when a user adds a comments make it update in real-time ) . Problem is meteor.js uses node.js (so javascript as server-side code). I use LAMP stack, Is it possible to get PHP to feed data into meteor.js from mysql.
Meteor is more than just an 'interactive webapplication'-builder or javascript framework. The idea is to have only one programming language (besides HTML/CSS for markup) to do all the work. Basically it creates a 'remote server' (in the clients browser) it can push data to and at the same time it publishes various API's to the users system. The data passed through these API's / connections has a specific structure which has to be adhered at all time.
Meteor is built around NodeJS, which makes it hard (if not impossible) to run it without this backend. Sure you can try to mimic the backend using PHP, but it would be a waste of time. Reading your question you'll be better of using a javascript framework like jQuery or Prototype. Unlike Meteor you will need to do the AJAX calls (POST & CallBack) yourself, but you can actually decide which backend you want to use yourself (including PHP / MySQL).
If you want to do this anyway you need to check the Meteor & NodeJS source code to see what the minimum requirements are to make Meteor run under PHP. The PHP stack has to interpret the commands Meteor sends and receivers, but this won't be an easy task.
You can use comet (or reverse ajax) for realtime updates.
Trying to marry node.js with PHP doesn't sound like a worthwhile path to go down. If someone insisted on using a system like Meteor.js, yet with a PHP back-end, it would make more sense to look at AngularJS which is mainly the client side.
Of course, that is different technology stack. If someone really insisted on the blending, one could consider using server side sockets to interact with PHP Web services; and/or use mongodb and/or mysql-node to interact with the same databases.
I released a meteorite package that interacts with a Wordpress site that has the Wordpress JSON API. A quick fix. For now.
Comes with a backend call that will return the raw data, or a publication that stores the posts using their id's instead of a randomly generated mongoid. And some basic templates to get you started including a Session variable that keeps track of the currently selected post.
I'm working on it a lot more and will eventually have a version that directly makes mysql calls from node so you won't need php or Wordpress; just the ability to access the mysql database (which can be remote, with the appropriate configuration, or on the same machine).
I have created a html page which sends custom data to a php file which then processes and evaluates it.
My next task is to make this into a GUI with the requirements:
1. A box for a custom search with button (it then posts this into the
php)
2. A box where xml/json request can be seen
3. A box where the xml/json response can be seen
4. A box where the parsed version is translated and made to look pretty.
***MUST CONNECT TO INTERNET, PHP ESTABLISHES CONNECTION BUT DO NOT WANT A GUI ISSUE
Any suggestions on programs or languages etc which can help me communicate with PHP in GUI form. It needs to be able to access the internet!
I was thinking perhaps Visual Basic as that's the only one I've ever used that really uses GUI's but I'm wondering what you all think!
Thanks!
Basically, what you're asking for is a web browser, with a very simple little HTML/Javascript front-end web page to make the PHP calls and display the results. I'm not entirely sure what it is about a browser environment that makes you think it's unsuitable, but it's basically exactly what you're asking for.
If a full-blown web browser really isn't suitable, you could try using a web browser control inside a simple GUI app. This would still work exactly the same, but would be without the browser controls, such as the URL bar.
Just use a browser.
If you don't want to do that -- build a browser.
If you are just looking for basically a web-based REST testing tool, try the Firefox RESTClient plug-in.
Why don't you use a framework ?
You may take a look here:
AppJS for Linux, Windows and Mac using HTML, CSS and Javascript
Adobe AIR : cross-platform using ActionScript/FLEX or HTML/Javascript
Titanium : HTML/CSS (no support anymore)
PhoneGap : mainly used for cross-phone-platform, but here's an Windows implementation of it (you should read the README.md ...)
You may also check this from Mozilla
I have a instance of Apache and IIS running on my server which i need to post data from the PHP application to the ASP.NET application .. is this action possible ? ,
if its possible what considerations
are required ?
if its not possible what are the
alternatives ? (Except - Webservices and socket programming)
because using web services or socket programming will not provide the overall requirement which i have on head !
I would look at this answer on super user
https://superuser.com/questions/149329/how-do-i-make-a-post-request-with-curl
Shows you how to do a post using cURL from PHP. You can just direct your post to your ASPX page.
I did something like this using Memcache, but I'm not shure thats what you want/need:
I put some data into the cache in PHP and read the same value out in .net, but its a little complicated when it comes to objects, but for basic value types it worked fine...