Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7398319
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T03:51:20+00:00 2026-05-29T03:51:20+00:00

I get a client is not defined error out of the following code: var

  • 0

I get a client is not defined error out of the following code:

var mysql = require('mysql');
var conf = {
  'database':'database',
  'user':'user',
  'password':'password'
};

function mysqlQuery(mysql, conf, query, callback) {
  var client = mysql.createClient({
    user:conf.user,
    password:conf.password
  });
  client.query('USE ' + conf.database, function () {
    client.query(query, callback);
  });
}

mysqlQuery(
  mysql,
  conf,
  'SELECT * FROM users;',
  function selectCb(err, results) {
    if (err) {
      throw err;
    }
    console.log(results);
    client.end();
  }
);

How can I pass the client variable to my callback function? I have no control on how the callback function will be called as it is called by the mysql module.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T03:51:21+00:00Added an answer on May 29, 2026 at 3:51 am

    You could bind [docs] client to callback. Inside the callback it will be available as this then:

    client.query(query, callback.bind(client))
    

    and

    this.end();
    

    You could also pass it as first parameter:

    client.query(query, callback.bind(null, client))
    

    or

    client.query(query, function(err, results) {
        callback(client, err, results);
    });
    

    where callback is defined as

    function selectCb(client, err, results) {..};
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I get the following error: Client does not support authentication protocol requested by server;
I can't work out how to get the mysql client to return the number
I get this error when running rails with mysql db. Basically it is not
I'm trying to get client-side javascript objects saved as a file locally. I'm not
I want to return an error code when the following error gets raised: Traceback
How do you get Client IP and Browser information using JSP?
I want to know how to get client IP address using jQuery? Is it
I can't seem to get client side validation working with the version of MVC
How can I get a client's address from a WCF Service Application? Also, is
Please let me know how to get the client IP address, I have tried

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.