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

Tuesday, February 1, 2022

[FIXED] Cannot connect to mysql database [phpmyadmin]

 February 01, 2022     connect, database, mysql, phpmyadmin, xampp     No comments   

Issue

  • to create databases I'm using xampp->phpyadmin,
  • I have created a database called "dungeons",
  • in my php code Im connecting to MySQL with this code:

    if ($_SERVER["SERVER_ADDR"]=="localhost")
    {
      define("SQL_HOST","localhost");
      define("SQL_DBNAME","dungeons");
      define("SQL_USERNAME",xxx);
      define("SQL_PASSWORD",xxx);
    } else {
      define("SQL_HOST","127.0.0.1");
      define("SQL_DBNAME","dungeons");
      define("SQL_USERNAME", xxx);
      define("SQL_PASSWORD",xxx);
    }
    
    mysql_connect(SQL_HOST, SQL_USERNAME, SQL_PASSWORD) or die("Cannot connect to mySQL: " . mysql_error());
    mysql_select_db(SQL_DBNAME) or die("Cannot connect to the database: ". mysql_error()); 
    

The error message says

Unknown database 'dungeons', when selecting db.

I don't have any idea where the problem is, since the database is made and I have successfully connected to the mysql with the code.


Solution

The error is correctly saying that the database is not available or not there. First create a new database in phpmyadmin and name it dungeons. After that try your script. Thank you



Answered By - Altaf Hussain
  • 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