Re: Connect to MySql
| From: | Jesper Juhl | Date: | Sat, 29 Jul 2000 14:47:39 +0000 |
| Subject: | Re: Connect to MySql | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-8958@lists.php.net to get a copy of this message | ||
> Hi all,
> How can I have access database table and output
> query result in HTML table using PHP and mySql?
> Thanks,
> Ourima
Here are the basics, for detailt see http://www.php.net/manual/ ,
http://www.php.net/manual/ref.mysql.php and
http://www.mysql.com/documentation/
<?php
$link = mysql_connect("mysqlserver.mydomain.com", "mysqlUserName",
"mysqlPassword");
mysql_select_db("foo", $link);
$result = mysql_query("SELECT * FRÓM bar", $link);
echo "<table>";
while($row = mysql_fetch_array($result)) {
echo "<tr>";
echo "<td>".$row["col_id"]."</td>";
echo "<td>".$row["name"]."</td>";
echo "</tr>";
}
echo "</table>";
?>
Assumptions made in the above code:
Your database server is "mysqlserver.mydomain.com" and allows connections
from the webserver with username "mysqlUserName" and password
"mysqlPassword". The database is named "foo" and has a table named
"bar"
with columns "col_id" and "name".
Best regards,
Jesper Juhl
juhl@eisenstein.dk