- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I want to connect my app to a mysql database to query and display information.
Is that something that is possible with Intel XDK?
- Tags:
- HTML5
- Intel® XDK
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Robert,
I'm using Dreamfactory to access MySQL from XDK (www.dreamfactory.com). It is an opensource tool that generates automatically the REST API that Elroy is suggesting to implement just connecting your database. It works very well, handles autentication and has a lot of features more.
Additional to MySQL, it works with several databases more, including some NoSQL, I think it worth take a look and dedicate some time to learn it and testing.
Once you get the basics feel free to PM me for some sample code to use it from XDK.
Regards,
Diego
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If you have a a mysql database on a server, I recommend implementing REST API on the server to allow access to the database entries from the client. Intel XDK allows you to create the application. It doesn't contain a feature to implement this for you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Robert,
I'm using Dreamfactory to access MySQL from XDK (www.dreamfactory.com). It is an opensource tool that generates automatically the REST API that Elroy is suggesting to implement just connecting your database. It works very well, handles autentication and has a lot of features more.
Additional to MySQL, it works with several databases more, including some NoSQL, I think it worth take a look and dedicate some time to learn it and testing.
Once you get the basics feel free to PM me for some sample code to use it from XDK.
Regards,
Diego
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Robert
I just create a web service on the mysql server. The web service can be php or asp.net and can return JSON data to your app.
Please search my other postings for example code.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I personally use webservices to retrieve JSON datas from website.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am going to give Dream Factory a try, If not I will try the other options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Diego,
I am developing an app for taking photos and location and upload them in a database (propably in phpMyAdmin). I also started using dreamfactory. Can you provide me some help on connecting the database with the xdk?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You can just use pure PHP, doing everything inside an iframe, that you host on a free hosting service.
This is the code you can use to connect to SQL
<?php $servername = "localhost"; $username = "username"; $password = "password"; // Create connection $conn = new mysqli($servername, $username, $password); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } echo "Connected successfully"; ?>
If you want to execute a query, you must use a code like this one:
$sql="Select * from Table_name"; $conn->query($sql);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Kiriakos,
Here is some sample code, it is for DreamFactory 2 or above.
//this function to connect, with a user defined in DF function logindf(mail, pass){ $.ajax({ type:'POST', beforeSend: function (request) { request.setRequestHeader('Content-Type','application/json'); request.setRequestHeader('X-DreamFactory-Api-Key','YourAPIKEY'); }, //urldf is your DreamFactory URL url: urlDf+'api/v2/user/session', data: '{"email":"'+mail+'", "password":"'+pass+'"}', success: function (response) { //save session in a global variable to use in other DF calls sesion = response.session_id; }, error: function (response) { alert('Se ha producido un error de acceso, por favor intente nuevamente'); console.log(JSON.stringify(response)); } }); //this is an example to get some data from a table $.ajax({ type:'GET', beforeSend: function (request) { request.setRequestHeader('X-DreamFactory-Application-Name', service); //the service name you set in DF request.setRequestHeader('X-DreamFactory-Session-Token', sesion); //the session from the login function request.setRequestHeader('X-DreamFactory-Api-Key','YourAPIKEY'); }, url: urlDf+'api/v2/'+service+'/_table/yourtable',//table name dataType: "json", success: function (data) { var len = data.resource.length; for (var i = 0; i < len; i++) { //process the result } }, error: function (response) { alert('Se ha producido un error al consultar la base de datos, por favor intente nuevamente'); alert(JSON.stringify(response)); } });
Regards
Diego
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Dream factory should be installed in the same host of the database in order to have access to the database, am I right? if it is installed in local copmuter it will not get the appropriate database, right?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Dreamfactory can connect to remote databases, you may install it anywhere.
Regards
Diego

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page