PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, February 20, 2022

[FIXED] Sometime I can't connect to mysql db with node.js while offline until I'm online, other time it just works, why?

 February 20, 2022     mysql, node.js, phpmyadmin     No comments   

Issue

My node.js program use the mysql module which I use with xampp. Why does it (sometime)require an internet connection to connect to my db in localhost using the mysql node module while other times it works fine while offline? It won't connect to my db which looks fine in phpmyadmin while offline but once I tried while online then it worked for a while offline then it seems to require internet once again. Why?


Solution

Behalf on using 'localhost' as your host you should use '127.0.0.1' That Will solve your problem

const host='127.0.0.1';
const user='root';
const password='root';
const database='node_db'

var connection = mysql.createConnection({
  host:host,
  user:user,
  password: password,
  database: database
})


Answered By - Pratik Hublikar
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing