官网上面有面向对象的写法,您可以到php官网参考一下。
mysqli的面向过程基本上和mysql的思路差不多,也是先连接,选择数据库,查询,取结果...
$sql = "SELECT * FROM table"
/* 连接 */
$con = mysqli_connect("localhost","user","password","dbname")
if (!$con)
{
die("连接错误: " . mysqli_connect_error())
}
/* 查询 */
$Result = mysqli_query($con,$sql)
/* 遍历结果集 */
while($data = mysqli_fetch_assoc($Result))
{
$Data_Username = $data["username"]
$Data_Password = $data["password"]
echo "用户名:{$Data_Username},密码:{$Data_Password}"
}
/* 释放查询结果 */
mysqli_free_result($Result)
/* 关闭连接 */
mysqli_close($con)
HTML:<form action="insert.php" method="post">
Firstname: <input type="text" name="firstname" />
Lastname: <input type="text" name="lastname" />
Age: <input type="text" name="age" />
<input type="submit" />
</form>
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)