# pyphp **Repository Path**: dreammo/pyphp ## Basic Information - **Project Name**: pyphp - **Description**: let you can use like php language to use python,include some function and PDO (base on pymysql) - **Primary Language**: Python - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2018-10-29 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ## pyphp Let you can use like php language to use python,include some function and PDO (base on pymysql). You can think 'dict' and 'list' is like 'array' in php to use PDO class,you can easy to operate mysql database. 此库可以让你像使用php一样去使用python,其中包括一些php常见的方法名称封装已经PDO操作mysql数据库(基于pymysql库). 你可以认为dict和list类型就是php中的array去操作PDO类库即可,很方便进行数据库操作。 ## How to use ? (如何使用?) ``` pip3 install phppy ``` or ``` pip install phppy ``` ## Example: use PDO connect mysql (例子: 使用PDO类连接mysql) ### init connect to mysql (初始化连接) ``` from phppy.pdo import PDO config = { "host":"localhost", "user":"root", "password":"root", "port":3306, "charset":"UTF8", "db":"db", "debug":True } try: connect = PDO(**config) #get databse connect object except Exception as e: print(e) ``` #### insert data (插入数据) ``` # insert many rows rows = [{"title":"hello world","conent":"conent"},{"title":"title2","conetnt":"content2"}] last_insert_id = connect.insert("table",rows) # insert single row row = {"title":"hello world","content":"content"} last_insert_id = connect.insert("table",row) ``` ### update data (更新数据) ``` where = {"id":1} update = {"title":"update"} # update table set title="update" where id = 1 affect_rows = connect.update("table",update,where) ``` ### delete data (删除数据) ``` where = {"id":1} # delete from table where id = 1 affect_rows = connect.delete("table",where) ``` ### select data (查询数据) ``` cols = ["title","id"] where = ["id":[1,2,3]] order = {"id":"DESC"} offset = 0 limit = 100 # select title,id from table where id in (1,2,3) order by id desc limit 0,100 rows = connect.select(cols,"table",where,order,offset,limit) ``` ### query sql (执行sql查询语句) ``` sql = 'select * from table limit 10' rows = connect.query(sql) ``` ### execute sql (执行语句) ``` sql = 'delete from table where id=1' result = connect.execute(sql) ``` ### get execute sql (获取已经执行的Sql语句) ``` get_sql = connect.get_sql() ```