At [02:39], I was at first thrown off by the destructuring syntax const {createPool}=require('mysql'); const pool = createPool( { … } ) ; An equivalent (more pedestrian) alternative would be something like: const mysql = require('mysql') ; const pool = mysql.createPool( { …} )
For those getting undefined, I used this code to connect to the database const mysql = require("mysql") //Create a Database Connection const con = mysql.createConnection({ host:'localhost', user:'root', password:'your_password', database:'your_databse' }) con.connect((err) => { if(err) { console.log(err) }else{ console.log("CONNECTION SUCCESSFUL!") } }) // Get The Data From The Table con.query('select * from your_table', (err, res) =>{ return console.log(res) })
For me it keeps saying 'undefined'. 😭 Could you help out how to fix that issue? I have node.js installed and triple checked if my code looks the same like in video.. 😕
hey! great video. i have a question, if i want to deploy this website on vercel/heroku what I need to do? our sql data base located in localhost how correctly i understand so can we push it somewhere? something like cloud storage? thanks for the answer :3
Hi, i want to store the return of the query in a variable. how can i make that work? When i write const x = (query) and instead of return console.log() just returning the res. It doesn't gave me back the result. Can anyone help me how to get the res returned to store it in a variable?
In your code, before the call to pool.query, create a variable, say, foo, then assign it the value of res within the function body: var foo=[] ; pool.query( 'SELECT * FROM apidb.users', (err,res)=>{foo=Array.from(res)} ) ; The value of foo will now be the result of the mysql query. To confirm that this code is working, run node in your shell, entering REPL mode, then give it the REPL command '.load database.js'. Node will echo the content of the file database.js followed by the result of running that file. You will remain in REPL mode: you can give the REPL command "foo", and node will echo its value. End the session by typing
@@LinXiaoChaun Why is it not working for me ? Btw i ive coded also something with react so dont be confused ;D const pool = createPool({ host: "localhost", user: "root", password: "" }) var foo = [] pool.query(`SELECT * FROM appclone.user`, (err, res) => {foo=Array.from(res)} ) res.json({"users": [foo] }) Could you help me ?
At [02:39], I was at first thrown off by the destructuring syntax
const {createPool}=require('mysql');
const pool = createPool( { … } ) ;
An equivalent (more pedestrian) alternative would be something like:
const mysql = require('mysql') ;
const pool = mysql.createPool( { …} )
For those getting undefined, I used this code to connect to the database
const mysql = require("mysql")
//Create a Database Connection
const con = mysql.createConnection({
host:'localhost',
user:'root',
password:'your_password',
database:'your_databse'
})
con.connect((err) => {
if(err)
{
console.log(err)
}else{
console.log("CONNECTION SUCCESSFUL!")
}
})
// Get The Data From The Table
con.query('select * from your_table', (err, res) =>{
return console.log(res)
})
you are the best Bro :) thanks
תותח אלוףףףףףף
ההסבר ממש מעולה ועוזר
תודה!🙏
short video and to the point. great job
awesome. finally i can connect the two!!! woo yea!!! Thank you sir :)
Quick and straight to the point.
Thank you so much for this, great tutorial!
Glad it was helpful!
For me it keeps saying 'undefined'. 😭 Could you help out how to fix that issue? I have node.js installed and triple checked if my code looks the same like in video.. 😕
Thanks for help
Always welcome
very useful, thank you for making the video
You're welcome 😊
Greate sir
Really useful video. By any chance, do you have a follow up video on how to post data to mysql work bench in javascript as well?
Thanks! And then? When you want to upload proyect to prod? What do I have to do to hide this information?
Thank you bro ❤
Hello Brother! Excellent Video, You just got a sub thank you so much. So simple and understandable. TY ❤❤
thank you bro
hey! great video. i have a question, if i want to deploy this website on vercel/heroku what I need to do? our sql data base located in localhost how correctly i understand so can we push it somewhere? something like cloud storage? thanks for the answer :3
Do we have to first create table insql
why didn't work on my visual studio code when I'll run in terminal? Pls. help!!
really good tutorial, just one question, how can i default select database name
Hey I have a error on require() function
Can we query same like php api ?
🐐 Thank you!
is require not defined anymore? i get "ReferenceError: require is not defined"
i applied your code but it just displays undefined what do i do?
Can uou show how to connect node express app to online MySQL database
how do i create a node module?
Hi, i want to store the return of the query in a variable. how can i make that work? When i write const x = (query) and instead of return console.log() just returning the res. It doesn't gave me back the result. Can anyone help me how to get the res returned to store it in a variable?
In your code, before the call to pool.query, create a variable, say, foo, then assign it the value of res within the function body:
var foo=[] ; pool.query( 'SELECT * FROM apidb.users', (err,res)=>{foo=Array.from(res)} ) ;
The value of foo will now be the result of the mysql query.
To confirm that this code is working, run node in your shell, entering REPL mode, then give it the REPL command '.load database.js'. Node will echo the content of the file database.js followed by the result of running that file.
You will remain in REPL mode: you can give the REPL command "foo", and node will echo its value.
End the session by typing
@@LinXiaoChaun Why is it not working for me ? Btw i ive coded also something with react so dont be confused ;D
const pool = createPool({
host: "localhost",
user: "root",
password: ""
})
var foo = []
pool.query(`SELECT * FROM appclone.user`, (err, res) => {foo=Array.from(res)} )
res.json({"users": [foo] })
Could you help me ?
For anyone getting an authentication error:
"npm install mysql2" then change the require statement to "mysql2"
thank u bro
Greate
mine said undefined
same
"undefined" occur as output of node database.js
please help regarding this
same did you find solution?
Maybe your password is not "rootuser".
@@nirmalgaur3228 Nope, because mines did the same thing and I used my password.
It occurs because you haven't select the database where the table reside
try to use mysql2 instead of mysql package
can this apply in phpmyadmin
I am getting a 504 error when sending data to mysql in nginx
video is blured
I guess it is playing in lower resolution in your system, you need to play in a higher resolution
ok