Not connecting to database with node.js

ساخت وبلاگ

آخرین مطالب

امکانات وب

Vote count: 0

I'm trying to connect and request queries from my database, but I wanna do it with JavaScript (or jQuery).

I'm trying this:

var mysql = require('mysql');

var con = mysql.createConnection({
  host: "localhost",
  user: "myUser",
  password: "myPassword",
  database: "mydb"

function GetSqlResult (sql_query) {
  con.connect(function(err) {
    if (err) throw err;
    //Select all customers and return the result object:
    con.query(sql_query, function (err, result, fields) {
      if (err) throw err;
      return result;

But I get this error:

Uncaught ReferenceError: require is not defined

I've tried using using the module "require.js" from this website

I still got the same error.

I want a solution for this error (if it exists), not an alternative.

I know that connecting to a database from JavaScript isn't very safe, but I really wanna do it, so I would love for someone to help me, please.

Thank you

asked 1 min ago
Mariana Leites

نویسنده : استخدام کار بازدید : 27 تاريخ : شنبه 1 ارديبهشت 1397 ساعت: 7:25

تبلیغات در اینترنت