Connect to a mysql database via php

Hello I try ti get data from a mysql server, so I a write a file on my server “API/waypoints.php” who read all the lines of my database and convert it to Json. When i go at this address with my browser it works. Well, ember’s side I go to “adapter/application.js” and put this

import DS from ‘ember-data’;

export default DS.JSONAPIAdapter.extend({ namespace: ‘API’, host: ‘’ });

when I make :‘waypoint’), It didn’t work because the the url made by the adapter is not How can I fix that’s? Server’s side or Ember’s side? thank for help Vincent

I’m new to this too, but it sounds like perhaps you have to extend the default JSONAPIAdapter and override the urlForFindAll method.

This should allow you to build the URL properly.

There might be a better way, but this should work.

Thank You It work, very easy to setup

Finaly I success to read data from mysql server I give my code if it can help somebody because I find few information about this subject

**//  adapters/applications.js**
import DS from 'ember-data';

export default DS.JSONAPIAdapter.extend({

    urlForFindAll(modelName, snapshot) {
         return '';

**// waypoints.php**

$servername = "localhost";
$username = "lamp";
$password = "lamp";
$dbname = "newdb";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);

$sql = "SELECT * FROM tripclic";
$result = $conn->query($sql);

$array = array();

while($row = $result->fetch_assoc())
        $attributes["attributes"] = $row;
        $attributes["id"]         = $row[id];
        $attributes["type"]       = "waypoints";

        array_push($array, $attributes);

// Finally, encode the array to JSON and output the results

$data = [ "data" => $array ];

echo json_encode( $data);

1 Like