Test Database Connection

A

Anonymous

Guest
i already set the server and install MySQL. How do i know whether the connection is right or not? what command to use to check everything is right or not? thanks
 
If you're just trying to see if it's working, just use any old MySQL client to log in and do a simple query.

If you're trying to see if PHP can access it, write a simple script to run a simple query (see the documentation).

Code:
SELECT 1 + 1 AS sum;
 
i'm using dreamweaver mx 2004 as the editor, i already install the mysql software, so what i need to do, where should i put the code? can u show me one by one, please? thanks for ur help :-D
 
Well i think swirlee answered your question!!
Just run that query using your mysql client!

Anyway...i think you wanna test it with php, right!?
I´ll assume that, so first use this next code to connect to your mysql database:
PHP:
<?php
$localhost ="localhost";
$dbuser="your_db_name";
$dbpass= "your_db_pass";
$dbname = "your_db_name";

mysql_connect($localhost, $dbuser, $dbpass) or die 
(mysql_error());
@mysql_select_db ("$dbname") or die(mysql_error());
?>
And to run that query, use:
Example:
PHP:
<?php
$result  =  mysql_query("SELECT 1 + 1 AS sum");
$row = mysql_fetch_assoc($result);
echo $row[sum];
?>
Check this for more information: MySQL Functions
 
i already try the command u gave me above but the following message show in the browser

Warning: mysql_connect(): Access denied for user: 'your_db_name@localhost' (Using password: YES) in c:\inetpub\wwwroot\Untitled-1.php on line 15
Access denied for user: 'your_db_name@localhost' (Using password: YES)

how do i correct it? thanks
 
You fill in the name of your database and username and password for $dbname and $dbuser and $dbpass.
 
i already install WAMP and MySQL software in my computer, are there crash? where should it find out those database name , use and etc? from where ? can u show please|?
 
kiwi said:
Warning: mysql_connect(): Access denied for user: 'your_db_name@localhost' (Using password: YES) in c:\inetpub\wwwroot\Untitled-1.php on line 15
Access denied for user: 'your_db_name@localhost' (Using password: YES)
Like swirlee said, it seems you didn´t filled in the database name, username and password for $dbname and $dbuser and $dbpass!
PHP:
<?
$dbuser="your database username here"; 
$dbpass= "your database password here"; 
$dbname = "your database name here";
?>
Just look at the error!!
 
really sorry to ask so much, i'm know nothing in PHP and MySQL, actually from where i should get the password, database name, and the user name? please, thanks a lot :eek:
 
MySQL is in your machine!?
Hunnn... to say the truth... i really don´t know!
I think it must be something like:
PHP:
$localhost ="localhost"; 
$dbuser="root"; 
$dbpass= ""; // There´s no password 
$dbname = "your_db_name"; // Your DB name here
I´m not sure about this, but you can try it anyway!
Don´t worry... a better solution will fall soon...!
 
i already mention above, i already install WAMP5 and i found out i'm using WinMySQLAdmin 1.4. If i want to edit or create some php file and to test those databse connection, where should i save the file and how to test the connection, should i need to configure the server in control panel? :)
 
Back
Top