这方法不太推荐,pdo比较靠谱~不过记录下,方便改老旧代码用。

<?php
$con = mysqli_connect("127.0.0.1","vas","password","test");
if (mysqli_connect_errno($con))
{
echo mysqli_connect_error();
die();
}
$sql = "SELECT * FROM test";
$result = mysqli_query($con, $sql);
while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
echo "{$row["id"]},{$row["val"]}n";
}
mysqli_free_result($result);
$sql = "INSERT INTO test (val) VALUES ('test');";
$result = mysqli_query($con, $sql);
mysqli_close($con);


Related Posts: PHP mysqli常见函数请求示例 :

留言