请问,PHP和MYSQL,怎样用面向对象的方法获取数据库里面字段的值,面向过程的我已经会了,注意是面向对象
发布网友
发布时间:2022-04-08 19:26
我来回答
共2个回答
热心网友
时间:2022-04-08 20:55
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>显示字段信息</title>
</head>
<body>
<?php
require_once("dbtools.inc.php");
$link = create_connection();
$sql = "SELECT * FROM PRICE WHERE category = '主板'";
$result = execute_sql("proct", $sql, $link);
echo "<table width='400' border='1'><tr align='center'>";
echo "<td>字段</td><td>数据类型</td><td>最大长度</td></tr>";
$i = 0;
while ($i < mysql_num_fields($result))
{
$meta = mysql_fetch_field($result, $i);
echo "<tr>";
echo "<td>$meta->name</td>";
echo "<td>$meta->type</td>";
echo "<td>$meta->max_length</td>";
echo "</tr>";
$i++;
}
echo "</table>" ;
mysql_close($link);
?>
</body>
</html>
热心网友
时间:2022-04-08 22:13
mysql_connect("hostname", "user", "password");
mysql_select_db("mydb");
$result = mysql_query("select * from mytable");
while ($row = mysql_fetch_object($result)) {
echo $row->user_id;
echo $row->fullname;
}
mysql_free_result($result);