View Full Version : connecting to mysql database
WILSOFT
10-02-2008, 11:29 AM
hie i'm a newbie and am having a problem connecting to my database..
the name of my database is wilsoft and it does not have a password..here is my code:
<html><?php
mysql_connect("localhost", "root", "") or die(mysql_error());
echo "Connected to MySQL";
?>
</html>
:confused:
maneetpuri
10-07-2008, 10:38 AM
Hi,
If executing this code you are getting output as "Connected to MySQL" means you are connected to the MySQL server, now the next step is selecting the database.
To select the database ythe function provided by PHP is mysql_select_db("name of the database"). Thus after add this line
mysql_select_db("") or die ("could not select database");
Once this is done you can then use PHP function mysql_query() to fire a query on the selected database and may use mysql_fetch_array() to fetch the result if you are firing a select query.
Hope this is helpful.
Cheers,
~Maneet
LeXolution IT Services (P) Ltd.
Web Development Company (http://www.lexolutionit.com)
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.