phpfunction connect&$error$username$password$dbname$host=localhost$port=3306$charset=utf8 $conn=mysqli_connect$host$username$password$dbname$port; if!$conn $error=iconvgbkutf-8mysqli_conn
代码无明显错误,但需要注意以下几点:
-
在函数内部使用了全局变量
$error,并用&引用传递。这种写法不太规范,建议将$error定义为函数的返回值。 -
在
read()函数中,判断$all的值后,只返回了一条结果,应该将return $lists;移到循环外部,以返回全部结果。 -
在
write()函数中,判断$insert的值后,应该分别返回mysqli_insert_id($conn)和mysqli_affected_rows($conn),而不是使用if-else语句返回。
原文地址: https://www.cveoy.top/t/topic/gtuX 著作权归作者所有。请勿转载和采集!