问题描述
我正在用电子做一个简单的时事通讯应用程序,我需要连接到我的数据库,但是如果我使用“require”来调用 MysqL 库,它会给我“require 未定义”,我尝试使用 browsify 但它没有用,有人可以帮助我吗? (此脚本位于 HTML 页面中)
<script>
document.getElementById("btn").addEventListener("click",() => {
var MysqL = require (['./node_modules/MysqL']);
var connection = MysqL.createConnection({
host: 'localhost',user: 'user',password: 'password',database: 'db',});
$sql = 'SELECT `id`,`first_name`,`last_name`,`email` FROM `subscribers`';
connection.query($sql,function (error,results,fields) {
if (error) throw error;
console.log(results);
$('#resultDiv').text(results[0].email);
});
connection.end();
})
</script>