我已经通过安装了节点js mysql和mysql类型
"@types/mysql": "^2.15.4",
"mysql": "^2.15.0"
我用电子和角2,所以在我的组件中,我想通过
import * as mysql from 'mysql'
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
})
export class AppComponent implements OnInit {
connection: any;
constructor() {
this.connection = mysql.createConnection({
host: 'localhost',
user: 'root',
password: '5378@Geowan5378',
database: 'company'
});
this.connection.connect((err) => {
if (err) {
console.log('error connecting', err);
}else{
console.log("connection was a success ");
}
});
} // DI
但现在有个错误
TypeError: o.createConnection is not a function
这是迄今为止唯一一个只学习电子和MySQL的组件。我哪里出错了?
请注意,当我调用
this.connection.connect
我不认为这可能是由网络库引起的,它在浏览器中不可用,但在我的情况下正在运行
electron .
要启动我的应用程序,请不要使用浏览器
或者我如何在不使用服务器端框架的情况下将应用程序直接连接到MySQL