Page 1 of 1

test Database Connection

Posted: Sat Mar 20, 2004 10:42 am
by kiwi
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

Posted: Sat Mar 20, 2004 1:39 pm
by swirlee
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 all

SELECT 1 + 1 AS sum;

test

Posted: Sun Mar 21, 2004 2:49 am
by kiwi
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

Posted: Sun Mar 21, 2004 5:45 am
by gesf
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());
?>[/php]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];
?>[/php]Check this for more information: MySQL Functions

Posted: Mon Mar 22, 2004 7:22 am
by kiwi
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

Posted: Mon Mar 22, 2004 11:08 am
by swirlee
You fill in the name of your database and username and password for $dbname and $dbuser and $dbpass.

Posted: Tue Mar 23, 2004 7:53 am
by kiwi
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|?

Posted: Tue Mar 23, 2004 9:08 am
by gesf
kiwi wrote: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";
?>[/php]Just look at the error!!

Posted: Tue Mar 23, 2004 9:29 pm
by kiwi
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:

Posted: Wed Mar 24, 2004 4:35 am
by gesf
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[/php]I´m not sure about this, but you can try it anyway!
Don´t worry... a better solution will fall soon...!

Posted: Wed Mar 24, 2004 7:29 am
by kiwi
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? :)