this code will return JSON format data and i want to use it in d3.js to show as a table…   But while using it showing like cant able to load the data, this is the error am getting, GET http://localhost:8080/NewWidget/widget/ui/data.php 404 (Not Found),   any leads will be helpful , thanks in advance    ">   this code will return JSON format data and i want to use it in d3.js to show as a table…   But while using it showing like cant able to load the data, this is the error am getting, GET http://localhost:8080/NewWidget/widget/ui/data.php 404 (Not Found),   any leads will be helpful , thanks in advance    ">   this code will return JSON format data and i want to use it in d3.js to show as a table…   But while using it showing like cant able to load the data, this is the error am getting, GET http://localhost:8080/NewWidget/widget/ui/data.php 404 (Not Found),   any leads will be helpful , thanks in advance    ">
Query external database in mendix custom widget - Mendix Forum

Query external database in mendix custom widget

0

Hi i am going with custom widget , in that widget i need to get my SQL data and need to compare with the another data. for that i am using php to get my sql data and use in it in js file. but i cant able to call my php file in the js file.

 

The below one in my PHP file ,

<?php

$username = "******";

$password = "******";

$host = "localhost";

$database="tc";

$server = mysql_connect($host, $username, $password);

$connection = mysql_select_db($database, $server);

 

$myquery = "SELECT '*' FROM `TBL_STUDENTS`";

$query = mysql_query($myquery);

if ( ! $query ) {

echo mysql_error();

die;

}

$data = array();

for ($x = 0; $x < mysql_num_rows($query); $x++) {

$data[] = mysql_fetch_assoc($query);

}

header("Access-Control-Allow-Origin: *");

echo json_encode($data);

mysql_close($server);

?>

 

this code will return JSON format data and i want to use it in d3.js to show as a table…

 


But while using it showing like cant able to load the data,

this is the error am getting,

GET http://localhost:8080/NewWidget/widget/ui/data.php 404 (Not Found),

 

any leads will be helpful , thanks in advance

 

 

asked
2 answers
1

Hi Narayana,

I would try to retrieve your data a different way. What you could do is specify a microflow to run in your custom widget that returns the data. So in this case use the client API to trigger a microflow. In your microflow use the database connector module to query your database and return the list of data to your custom widget. From there you can do whatever you need to do with that data in your .js file. 

Another option could be to consume the data through OData in javascript. You would have to expose your data in your external db. A couple of quick google searches will pull up some examples of how to do this.

 

Hope this helps!

answered
0

Mendix will probably recommend you do this with a web request, Check out refguide/call-rest-action then create some Mendix tables and go from there.

What you are trying to do is pretty interesting and completely possible but will probably be frowned upon. Ensure you are running your PHP on the same host, but a different port from Mendix, then try the same.

Mendix is a big proponent of Dojo, so you might also want to check out dojo.xhrGet and related functions

answered