这篇文章主要为大家详细介绍了PHP操作MySQL函数分析,MySQL和php交互函数的简单示例,具有一定的参考价值,可以用来参考一下。
感兴趣的小伙伴,下面一起跟随四海网的小编小韵来看看吧!
1. 建立和关闭连接代码如下:
$link1 = @mysql_connect(“server1″, “webuser”, “password”)
or die(“Could not connect to mysql server!”);
@mysql_select_db(“company”) or die(“Could not select database!”);
$query = “select id, name from product order by name”;
$result = mysql_query($query);
$id = mysql_result($result, 0, “id”);
$name = mysql_result($result, 0, “name”);
mysql_close();
代码如下:
…
for ($i = 0; $i <= mysql_num_rows($result); $i++)
{
$id = mysql_result($result, 0, “id”);
$name = mysql_result($result, 0, “name”);
echo “Product: $name ($id)”;
}
…
代码如下:
…
$query = “select id, name from product order by name”;
$result = mysql_query($query);
while(list($id, $name) = mysql_fetch_row($result)) {
echo “Product: $name ($id)”;
}
…
代码如下:
…
$query = “select id, name from product order by name”;
$result = mysql_query($query);
while($row = mysql_fetch_array($result, MYSQL_BOTH)) {
$name = $row['name'];//或者 $name = $row[1];
$name = $row['id'];//或者 $name = $row[0];
echo “Product: $name ($id)”;
}
…
代码如下:
…
$query = “select id, name from product order by name”;
$result = mysql_query($query);
while($row = mysql_fetch_object($result)) {
$name = $row->name;
$name = $row->id;
echo “Product: $name ($id)”;
}
…
代码如下:
mysql_connect(“localhost”, “name”,”pwd”);
$dbs = mysql_list_dbs();
while (list($db) = mysql_fetch_row(dbs)) {
echo “$db <br>”;
}
代码如下:
<?php
$conn = new COM(“ADODB.Connection”) or die(“Cannot start ADODB.Connection”);
$conn->Open(“Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\\php5\\netBook.mdb”);
$rs = $conn->Execute(“select * from manage”); // 记录集
$num_columns = $rs->Fields->Count();
echo $num_columns . “<br />\n”;
for ($i=0; $i < $num_columns; $i++) {
$fld[$i] = $rs->Fields($i);
}
$rowcount = 0;
while (!$rs->EOF) {
for ($i=0; $i < $num_columns; $i++)
{
echo htmlspecialchars($fld[$i]->value) . “\t”;
}
echo “<br />\n”;
$rowcount++; // rowcount 自增
$rs->MoveNext();
}
$rs->Close(); //关闭数据集
$conn->Close();
?>
本文来自:http://www.q1010.com/173/12993-0.html
注:关于PHP操作MySQL函数分析,MySQL和php交互函数的简单示例的内容就先介绍到这里,更多相关文章的可以留意四海网的其他信息。
关键词:
四海网收集整理一些常用的php代码,JS代码,数据库mysql等技术文章。