跟着视频上的敲的,他那可以运行,我这有问题,根据调试,数据库连接上了,在query这个函数上的问题,
代码如下
const mysql = require("mysql");
let connection = mysql.createConnection({
host: "localhost/phpMyAdmin",
user: "root",
password: "",
database: "onepiece"
});
connection.connect();
let sql = "select * from users where id=1";
connection.query(sql, function(err, results, fields){
if (err) throw err;
console.log("---------------------");
console.log(results);
console.log("---------------------");
});
connection.end();
错误信息如下
Error: getaddrinfo ENOTFOUND localhost/phpMyAdmin/index.php
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:60:26)
--------------------
at Protocol._enqueue (C:\Users\QingChen\Desktop\Develop\Nodejs\6-optionSql\node_modules\mysql\lib\protocol\Protocol.js:144:48)
at Protocol.handshake (C:\Users\QingChen\Desktop\Develop\Nodejs\6-optionSql\node_modules\mysql\lib\protocol\Protocol.js:51:23)
at Connection.connect (C:\Users\QingChen\Desktop\Develop\Nodejs\6-optionSql\node_modules\mysql\lib\Connection.js:119:18)
at Object. (C:\Users\QingChen\Desktop\Develop\Nodejs\6-optionSql\db.js:11:12)
at Module._compile (internal/modules/cjs/loader.js:936:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:947:10)
at Module.load (internal/modules/cjs/loader.js:790:32)
at Function.Module._load (internal/modules/cjs/loader.js:703:12)
at Function.Module.runMain (internal/modules/cjs/loader.js:999:10)
at internal/main/run_main_module.js:17:11 {
errno: 'ENOTFOUND',
code: 'ENOTFOUND',
syscall: 'getaddrinfo',
hostname: 'localhost/phpMyAdmin/index.php',
fatal: true
}