altruios / responce
这个项目的目的是让数据库交互变得更简单,它向客户端发送JSON数据,并警告客户端错误
dev-main
2021-07-05 20:45 UTC
Requires
- php: >=7.4
- another-vendor/package: 1.*
This package is auto-updated.
Last update: 2024-09-06 04:09:06 UTC
README
php数据库访问模式
使用
<?php #include inits a $__RESPONCE variable include_once('./__RESPONCE.php'); #other boiler plate and database connections #assuming here mysql setup - so below is boiler plate for that /* Open a connection */ $mysqli = new mysqli("localhost", "root", "", "example"); /* check connection */ if (mysqli_connect_errno()) { #error handling though the responce object $__RESPONCE->message="connect failed"; $__RESPONCE->add_error(mysqli_connect_error())); #send calls exit $__RESPONCE->send(); } $sql = "sql query here"; $stmt = $conn->query($sql); if ($stmt->error){ $__RESPONCE->message="failed statement"; $__RESPONCE->add_error($stmt->error); $__RESPONCE->send(); } else{ while ($row = $stmt->fetch_assoc()){ #mysql_table_row_to_object turns a mysql table row... into an object $data = $__RESPONCE->mysql_table_row_to_object($row); #you may want to modify data before you add it - to mysql_table_row_to_object returns the object #or more complicated queries. $__RESPONCE->add_data($data); } } $__RESPONCE->message = "all clear captain my captain"; $__RESPONCE->send(); ?>
希望这会有所帮助
这是alpha版本 - 随着时间的推移将进行改进 :)