-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unable to store mysql query result inside a variable #2458
Labels
Comments
The const checkEmailUsed = (email) => {
let sql = "SELECT * FROM users_signup WHERE user_email = ? LIMIT 1";
return new Promise((resolve, reject) => {
conn.query(sql, email, (err, res) => {
if (err) {
reject(err);
return;
}
resolve(res[0]);
});
conn.end();
});
};
var user = [];
checkEmailUsed("mikias@email.com")
.then((res) => user.push(res))
.then(() => console.log(user))
.catch((err) => console.log(err)); |
Thank you very much sir. Thank you
…On Thu, Jan 21, 2021 at 2:11 AM Marco Baumgartl ***@***.***> wrote:
The console.log is executed before the promise is fulfilled. This should
work:
const checkEmailUsed = (email) => {
let sql = "SELECT * FROM users_signup WHERE user_email = ? LIMIT 1";
return new Promise((resolve, reject) => {
conn.query(sql, email, (err, res) => {
if (err) {
reject(err);
return;
}
resolve(res[0]);
});
conn.end();
});};
var user = ***@***.***")
.then((res) => user.push(res))
.then(() => console.log(user))
.catch((err) => console.log(err));
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#2458 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AJOBECIEMRMZS6W3UXHUGPDS274URANCNFSM4WKFMN4A>
.
|
@mikias21 can you mark this issue as closed? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I am trying to query user by email and save the result inside a variable. I tried using await and async, callback and promise but
none of them actually work.
The text was updated successfully, but these errors were encountered: