Current location: Hot Scripts Forums » Programming Languages » PHP » How Can i connect sql database with php? I'm New in PHP


How Can i connect sql database with php? I'm New in PHP

Reply
  #1 (permalink)  
Old 06-01-04, 08:04 AM
zahid zahid is offline
New Member
 
Join Date: Jun 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Question How Can i connect sql database with php? I'm New in PHP

Hello Every Body.
M is new in PHP. I have a problem. I have write a book example which get all built-in database names and show.
When i run this example it show me nothing. it also did not show me any error.
PLease help me in this matter. Bcz i have to make a php database project.

I have install
IIS 5.0
PHP Version 4.3.6 (Executeable, setup)
Sql(Mysql server and client 4.0.2.0a) setup
All settings are by default.
Code is here.


<?php
$host = "localhost";
$user = "";
$password = "";
?>
<select name="database" size="1">
Please select the database..
<?php
mysql_connect($host, $user, $password);
$db_table = mysql_list_dbs();
for ($i = 0; $i < mysql_num_rows($db_table); $i++)
{
echo("<option>" . mysql_tablename($db_table, $i));
}
?>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 06-01-04, 11:12 AM
Guitarist49862 Guitarist49862 is offline
Newbie Coder
 
Join Date: Jun 2004
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
This Should Work...

<?php
$host = "localhost";
$usr = "your_username";
$pw = "your_password";
?>
<select name="database" size="1">
Please select the database...
<?php
$conn = mysql_connect($host, $usr, $pw);
$result = mysql_list_dbs($conn);
while($row = mysql_fetch_object( $result )) {
print "<option>".$row[database]."</option>";
}
?>
</select>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP Form to update a MySQL database? Scoobler PHP 9 09-04-08 02:41 AM
How do i search from a form to mysql database using php QTortZ PHP 6 06-02-04 10:57 PM
question about updating a page or database for an, php and mysql updating mikewooten PHP 1 02-12-04 01:11 AM
Unable to connect to MSSQL with PHP through a firewall whiplashdomain PHP 1 01-31-04 08:17 PM
change my field in this example sal21 ASP 3 07-14-03 03:49 AM


All times are GMT -5. The time now is 01:24 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.