Go Back   HostGator Peer Support Forums > HostGator Peer Support Forums > Web Hosting Services

Notices

Reply
 
Thread Tools
  #1  
Old 03-07-2007, 01:33 AM
webadmin webadmin is offline
Hatchling Croc
 
Join Date: Mar 2007
Posts: 1
Default Connect MySQL Database with PHP

Hi Everybody,

I am trying to create & access MySql Database using PHP. Can anybody send me a very simple (or not simple) PHP codes which creates & which can access & get information from the database?
Reply With Quote
  #2  
Old 03-07-2007, 06:15 AM
riostyles riostyles is offline
Royal Croc
 
Join Date: Jan 2006
Location: Rio de Janeiro, Brazil
Posts: 765
Default Re: Connect MySQL Database with PHP

http://br.php.net/manual/en/ref.mysql.php
Go down the page to table of contents.
See also
http://br.php.net/manual/en/function...etch-array.php

<?php
// Connecting, selecting database
$link = mysql_connect('mysql_host', 'mysql_user', 'mysql_password')
or die('Could not connect: ' . mysql_error());
echo 'Connected successfully';
mysql_select_db('my_database') or die('Could not select database');

// Performing SQL query
$query = 'SELECT * FROM my_table';
$result = mysql_query($query) or die('Query failed: ' . mysql_error());

// Printing results in HTML
echo "<table>\n";
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo "\t<tr>\n";
foreach ($line as $col_value) {
echo "\t\t<td>$col_value</td>\n";
}
echo "\t</tr>\n";
}
echo "</table>\n";

// Free resultset
mysql_free_result($result);

// Closing connection
mysql_close($link);
?>
Reply With Quote
Reply

Bookmarks

Thread Tools

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 On
HTML code is Off

Forum Jump

All times are GMT -5. The time now is 11:53 AM.