php yaf SQL,新增yaf_db模块 by caohao-php · Pull Request #428 · laruence/yaf · GitHub

Catalogue

1.Instruction

2.Requirement

3.Create test table

4.Start yaf_db

5.Init yaf_db connection

6.Native SQL query

7.Error Info

8.Where statement

9.Select statement

10.Insert statement

11.Replace statement

12.Update statement

13.Delete statement

14.Whole Example

15.Database Transaction

16.Data Caching

17.MySQL Database Connection Pool

18.Redis Connection Pool

Instruction

1、Fast : yaf_db is an mysql database ORM written in c, built in php extension, as we known, database ORM is a very time-consuming operation, especially for interpretive languages such as PHP, and for a project, the proportion of ORM is very high,so here I will implement the MySQL ORM operation in C language, and use the performance of C language to improve the performance of ORM.

2、Safe : yaf_db can solve SQL injection through parameter binding.

3、Powerful : concise and powerful usage , support any operation in database.

4、Easy : Extremely easy to learn and use, friendly construction.

5、Data-cache : yaf_db supports data caching. You can use redis as a medium to cache database data, but remember that when the update, insert, and delete operations involve caching data, you need to delete your cache to ensure data consistency.

6、Connection-pool : yaf_db uses a special way to establish a stable connection pool with MySQL. performance can be increased by at least 30%, According to PHP's operating mechanism, long connections can only reside on top of the worker process after establishment, that is, how many work processes are there. How many long connections, for example, we have 10 PHP servers, each launching 1000 PHP-FPM worker processes, they connect to the same MySQL instance, then there will be a maximum of 10,000 long connections on this MySQL instance, the number is completely Out of control! And PHP's connection pool heartbeat mechanism is not perfect

1、快速 - yaf_db是一个为PHP扩展写的纯C语言写的mysql数据库ORM扩展,众所周知,数据库ORM是一个非常耗时的操作,尤其对于解释性语言如PHP,而且对于一个项目来说,ORM大多数情况能占到项目很大的一个比例,所以这里我将MySQL的ORM操作用C语言实现,利用C语言的性能,提升ORM的性能。

2、安全 - yaf_db能通过参数绑定的方式解决SQL注入的问题。

3、强大 - 便捷的函数,支持所有数据库操作。

4、简单 - 使用和学习非常简单,界面友好。

5、数据缓存 - yaf_db支持数据缓存,你可以采用redis作为介质来缓存数据库的数据,但是记得在update、insert、delete 操作涉及到与缓存数据相关的数据修改时,需要按key删除您的缓存,以保证数据一致性。

6、连接池 - yaf_db通过一种特殊的方式来建立一个稳定的与MySQL之间的连接池,性能至少能提升30%,按照 PHP 的运行机制,长连接在建立之后只能寄居在工作进程之上,也就是说有多少个工作进程,就有多少个长连接,打个比方,我们有 10 台 PHP 服务器,每台启动 1000 个 PHP-FPM 工作进程,它们连接同一个 MySQL 实例,那么此 MySQL 实例上最多将存在 10000 个长连接,数量完全失控了!而且PHP的连接池心跳机制不完善。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值