note 45502 added to ref.mysql
| From: | sallas at NOSPAM dot sackratte dot net | Date: | Thu, 09 Sep 2004 09:07:54 +0000 |
| Subject: | note 45502 added to ref.mysql | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-76284@lists.php.net to get a copy of this message | ||
Here is a good example to begin with mysql and php
have fun
|sa||as|=|sa||as@sackratte.net|=|http://www.sackratte.net|
<?PHP
### connect to database
$db = mysql_connect("www.sackratte.net", "user", "pass123") or die
("<br><i>ERROR</i> in connect function (" . mysql_errno() . ":
" . mysql_error() . ")\n");
### select database
mysql_select_db("friends", $db) or die ("<br><i>ERROR</i> in
connect function (" . mysql_errno() . ": " . mysql_error() . ")\n");
### request information from database
$result = mysql_query("SELECT fname, sname, phone, cellphone, mail FROM addresses ORDER BY
sname", $db);
if (!$result) { echo "Error in mysql_query (" . mysql_errno() . ": " .
mysql_error() . ")\n"; exit; }
### display number of friends in database
$num_entries = mysql_num_rows($result);
echo $num_entries . " friends in database";
### show result
echo '<table>';
# this is the tables header , background color is grey
echo '<tr bgcolor="#cccccc"><td>Name</td><td>First
Name</td><td>Phone</td><td>Cellphone</td><td>Mail</td></tr>';
while ($friend = mysql_fetch_object($result)) {
echo '<tr><td>' . $friend->sname . '</td><td>' .
$friend->fname . '</td><td>' . $friend->phone.
'</td><td>' . $friend->cellphone. '</td><td>' .
$friend->mail . '</td></tr>';
}
echo '</table>';
### close database connection
mysql_close($db);
?>
----
Manual Page -- http://www.php.net/manual/en/ref.mysql.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+45502
Delete -- http://master.php.net/manage/user-notes.php?action=delete+45502&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+45502&report=yes
Search -- http://master.php.net/manage/user-notes.php