简体   繁体   中英

Connecting my React App to a MySQL Database on a PHP Server

I am new to working with data bases. I have a react app that I would like to connect to a MySQL database. The server is not mine but given by a web provider (strato), using PHP.

Is it generally possible to GET and PUT data via react (meaning javascript) to this data base in a way that I normally work with ajax and a restful API?

I really hope this question provides enough information for an answer :)

Here's a code example from https://github.com/numtel/reactive-mysql-example , file index.js. Have a look at that file and settings.js to see how to set up the connection.

var results = liveDb.select('select * from players order by score desc', [ {
  table: 'players'
} ]).on('update', function(diff, data){

  var msg = JSON.stringify({
    type: 'diff',
    data: diff
  });

  // Send change to all clients
  connected.forEach(function(conn){
    conn.write(msg);
  });

});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM