- Forums
- PHP
- How To Test MySQL Database Connection Includes A Free PHP Script
A simple tutorial guide that explains how to test a MySQL database connections. Will explain step by step how to test the connection to a database using PHP example code. You can also download the complete script for free. This is a tutorial for beginners [2063], Last Updated: Mon Jun 24, 2024
Webune Tutorials
Sat Dec 10, 2011
30 Comments
3464 Visits
Hello,
Welcome to Webune Support Forums - We provide PHP hosting with MySQL database. Our support and service is unmatched. We are developers like you and we know what PHP developers needs.
Today we are sharing a very useful script written in PHP to test your database connection. This easy and simple to use script will help you confirm the login information you have been given is correct.
For example, lets say you have a script which uses a MySQL database, but you are getting connection errors like:
Access denied for user 'admin'@'localhost' (using password: NO)
This error simply means you don't have the correct database information like your username because the script tried to connect to your database but it was unsuccessful.
NOTE: If you don't want to download the script provided in this post, you can create the script yourself by following the steps provide on this post:
Testing Mysql Database Connection Scriptstep 1. Download the script provided in this post
step 2. Unzip it and upload the testmysql/ folder to your server where you have PHP and a MySQL database.
step 3. Once you have uploaded the files to your web site, test it by accessing the script to where you place it in your site. for example:
http://www.example.com/testmysql/test-mysql.php
please give us any comments or tips.
Thanks
Webune Support Team
UPDATE: After reading some of your replies, there are some of you that are having trouble because no errors show up. If this is true for you, probably your PHP configuration is setup to hide errors, what you can do is add this line at the beginning of our script:
add this line:
ini_set('display_errors', 1);this will ensure that if you have any errors, it will show up
Please leave your comments, we appreciate your input.
testmysql.zip