我正在尝试在繁琐的库的帮助下使用连接字符串连接到远程 mysql 服务器。我将所有代码从 react 转换为 react-es6。当我尝试如下进行连接时,出现错误“未定义不是函数”。
class APP extends React.Component {
constructor(props) {
alert("hai");
console.log("hai");
super(props);
this.state = {
result: [],
RecNo: ""
};
}
getZipData(){
alert("hello");
var Connection = require('tedious').Connection;
console.log("connection:"+Connection)
Request = require('tedious').Request;
console.log("request:"+Request);
var config = {
userName: 'xx',
password: 'xxxxxx',
server: 'xxxxxxxxx',
options: {
database: 'xxxxxxx'
}
};
alert("shaik"+JSON.stringify(config));
var connection = new Connection(config); //getting error here
alert("connected")
connection.on('connect',(err)=> {
console.log("connected");
if (err) {
console.log(err)
}
//executeStatement();
var sql = "SELECT * FROM xxxx";
return new Promise(
function(resolve,reject){
var data = [];
var request = new Request(sql,[],(row)=>{
data.push(row);
},
(error)=>{
if(error){
reject(error);
}else{
resolve(data);
}
});
}
)
connection.execSql(request);
console.log("hai:")
});
}
componentWillMount() {
this.getZipData()
alert("data:");
}
render(){
return(
<p>Hello</p>
)
}
}
React.render(<APP/>,document.getElementById('app'));
我无法建立连接。可能存在语法错误,因为我是新手。