将我的React应用程序连接到PHP服务器上的MySQL数据库
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 :)
我是处理数据库的新手。 我有一个反应应用程序,我想连接到MySQL数据库。 服务器不是我的,而是由Web提供商(strato)使用PHP提供。 p>
通常可以通过react(意味着javascript)将GET和PUT数据添加到此数据库中 我通常使用ajax和一个安静的API的方式吗? p>
我真的希望这个问题提供足够的信息来回答:) p> div>
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);
});
});