note 76044 deleted from faq.databases by felipe
| From: | felipe@php.net | Date: | Tue, 22 Apr 2008 01:10:56 +0000 |
| Subject: | note 76044 deleted from faq.databases by felipe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-138639@lists.php.net to get a copy of this message | ||
Note Submitter: me at hotmail dot com
----
To access a SQL database you can just use this code:
<?php
$db = mysql_connect ("localhost", "<userName>",
"<password>") or die ('I cannot connect to the database because: ' .
mysql_error());
mysql_select_db ("<database_name>");
$sql = "SELECT * FROM table";
$res = mysql_query($sql, $db) or die(mysql_error());
while ($row = mysql_fetch_object($res)) {
print $row->column1;
print <br />;
print $row->column2;
}
mysql_free_result ($res);
?>