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) })
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 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 ?
תותח אלוףףףףףף
ההסבר ממש מעולה ועוזר
תודה!🙏
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
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( { …} )
short video and to the point. great job
Quick and straight to the point.
Thanks! And then? When you want to upload proyect to prod? What do I have to do to hide this information?
awesome. finally i can connect the two!!! woo yea!!! Thank you 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?
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.. 😕
Hello Brother! Excellent Video, You just got a sub thank you so much. So simple and understandable. TY ❤❤
Do we have to first create table insql
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
Thank you so much for this, great tutorial!
Glad it was helpful!
why didn't work on my visual studio code when I'll run in terminal? Pls. help!!
very useful, thank you for making the video
You're welcome 😊
really good tutorial, just one question, how can i default select database name
For anyone getting an authentication error:
"npm install mysql2" then change the require statement to "mysql2"
thank u bro
Can uou show how to connect node express app to online MySQL database
Hey I have a error on require() function
Can we query same like php api ?
Thank you bro ❤
how do i create a node module?
Greate sir
Thanks for help
Always welcome
i applied your code but it just displays undefined what do i do?
is require not defined anymore? i get "ReferenceError: require is not defined"
thank you bro
mine said undefined
same
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 ?
"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
🐐 Thank you!
can this apply in phpmyadmin
video is blured
I guess it is playing in lower resolution in your system, you need to play in a higher resolution
Greate
I am getting a 504 error when sending data to mysql in nginx
ok