PHPでMySQLデータベースに接続する基本操作方法

PHPコード:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8″ />
<?php
echo “this is a sample for opeartion database</br>";
echo “php connect mysql sample";

$mysql_server_name="localhost";
$mysql_username="root";
$mysql_password="pwdstartnews24″;
$mysql_database="dbstartnews24″;

$conn=mysql_connect($mysql_server_name, $mysql_username,
$mysql_password);

$strsql="SELECT * FROM `tbls`";
$result=mysql_db_query($mysql_database, $strsql, $conn);
$row=mysql_fetch_row($result);

echo '<font face="verdana">’;
echo '<table border="1″ cellpadding="1″ cellspacing="2″>’;

echo “</b><tr></b>";
for ($i=0; $i<mysql_num_fields($result); $i++)
{
echo '<td bgcolor="#fac"><b>’.
mysql_field_name($result, $i);
echo “</b></td></b>";
}
echo “</tr></b>";
mysql_data_seek($result, 0);
while ($row=mysql_fetch_row($result))
{
echo “<tr></b>";
for ($i=0; $i<mysql_num_fields($result); $i++ )
{
echo '<td bgcolor="#abe">’;
echo $row[$i];
echo '</td>’;
}
echo “</tr></b>";
}

echo “</table></b>";
echo “</font>";
mysql_free_result($result);
mysql_close($conn);
?>

PHP

Posted by arkgame