PHP怎么直接修改表内容DataGrid功能实现代码
分类:PHP_Python| 发布:佚名| 查看:294 | 发表时间:2016/2/15
由于需要连接Oracle所以从二次开发和页面样式来说个人觉得phpMyDataGrid还是比较好上手。
1. 创建测试数据库和表
01 | create database `camnpr`; |
05 | CREATE TABLE `employees` ( |
06 | `id` int (6) NOT NULL auto_increment, |
07 | ` name ` char (20) default NULL , |
08 | `lastname` char (20) default NULL , |
09 | `salary` float default NULL , |
10 | `age` int (2) default NULL , |
11 | `afiliation` date default NULL , |
12 | `status` int (1) default NULL , |
13 | `active` tinyint(1) default NULL , |
14 | `workeddays` int (2) default NULL , |
15 | `photo` char (30) default NULL , |
19 | insert into `employees` |
20 | (`id`,` name `,`lastname`,`salary`,`age`,`afiliation`,`status`,`active`,`workeddays`,`photo`) |
21 | values (1, 'Ana' , 'Trujillo' ,2000,45, '2005-05-13' ,1,1,10, '1.jpg' ); |
22 | insert into `employees` |
23 | (`id`,` name `,`lastname`,`salary`,`age`,`afiliation`,`status`,`active`,`workeddays`,`photo`) |
24 | values (2, 'Jennifer' , 'Aniston' ,3500,23, '2004-10-22' ,1,0,0, '2.jpg' ); |
25 | insert into `employees` |
26 | (`id`,` name `,`lastname`,`salary`,`age`,`afiliation`,`status`,`active`,`workeddays`,`photo`) |
27 | values (3, 'Michael' , 'Norman' ,1200,19, '2007-01-10' ,1,1,5, '3.jpg' ); |
28 | insert into `employees` |
29 | (`id`,` name `,`lastname`,`salary`,`age`,`afiliation`,`status`,`active`,`workeddays`,`photo`) |
30 | values (4, 'Vanessa' , 'Black' ,6500,31, '2000-11-05' ,1,1,30, '4.jpg' ); |
31 | insert into `employees` |
32 | (`id`,` name `,`lastname`,`salary`,`age`,`afiliation`,`status`,`active`,`workeddays`,`photo`) |
33 | values (5, 'Michael' , 'Strauss' ,3200,45, '2006-10-21' ,2,0,22, '5.jpg' ); |
34 | insert into `employees` |
35 | (`id`,` name `,`lastname`,`salary`,`age`,`afiliation`,`status`,`active`,`workeddays`,`photo`) |
36 | values (6, 'William' , 'Brown' ,2300,21, '2001-03-10' ,3,1,10, '6.jpg' ); |
37 | insert into `employees` |
38 | (`id`,` name `,`lastname`,`salary`,`age`,`afiliation`,`status`,`active`,`workeddays`,`photo`) |
39 | values (7, 'Lucca' , 'Normany' ,2800,36, '2006-10-02' ,3,1,20, '7.jpg' ); |
2. PHP程序介绍
phpMyDataGrid主要是通过phpmydatagrid.class.php,dgscripts.js来实现的,总共加起来不到100kB,又是一个小巧的软件。对于这两个文件就不多讲了,感兴趣的同学可以“打包带走”回去慢慢品。主要介绍该软件的使用方法,即实例 datagrid_for_mysql.php。先看一下页面示意图:

程序讲解:
02 | include ( "phpmydatagrid.class.php" ); |
03 | $objGrid = new datagrid; |
04 | $objGrid ->closeTags(true); |
05 | $objGrid ->friendlyHTML(); |
06 | $objGrid ->methodForm( "get" ); |
08 | $objGrid ->conectadb( "127.0.0.1" , "root" , "root" , "camnpr" ); |
09 | $objGrid ->salt( "Myc0defor5tr0ng3r-Pro3EctiOn" ); |
10 | $objGrid ->language( "en" ); |
12 | $objGrid ->buttons(true,true,true,true); |
14 | $objGrid ->form( 'employee' , true); |
16 | $objGrid ->searchby( "name,lastname" ); |
18 | $objGrid ->tabla( "employees" ); |
20 | $objGrid ->keyfield( "id" ); |
22 | $objGrid ->datarows(20); |
24 | $objGrid ->orderby( "name" , "ASC" ); |
26 | $objGrid ->FormatColumn( "id" , "ID Employee" , 5, 5, 1, "50" , "center" , "integer" ); |
27 | $objGrid ->FormatColumn( "name" , "Name" , 30, 30, 0, "150" , "left" ); |
28 | $objGrid ->FormatColumn( "lastname" , "Last name" , 30, 30, 0, "150" , "left" ); |
29 | $objGrid ->FormatColumn( "age" , "Age" , 5, 5, 0, "50" , "right" ); |
30 | $objGrid ->FormatColumn( "afiliation" , "Afiliation Date" , 10, 10, 0, "100" , "center" , "date:dmy:/" ); |
31 | $objGrid ->FormatColumn( "status" , "Status" , 5, 5, 0, "60" , "left" , "select:1_Single:2_Married:3_Divorced" ); |
33 | $objGrid ->FormatColumn( "active" , "Active" , 2, 2, 0, "50" , "center" , "check:No:Yes" ); |
34 | $objGrid ->FormatColumn( "salary" , "Salary" , 10, 10, 0, "90" , "right" , "money:€" ); |
35 | $objGrid ->FormatColumn( "workeddays" , "Work days" , 5, 2, 0, "50" , "right" , "chart:percent:val:31" ); |
38 | $objGrid ->ajax( 'silent' ); |
40 | <head><title>PHPDataGrid</title></head> |
41 | <body><div align= "center" > |
45 | echo '</div></body></html>' ; |
46 | $objGrid ->desconectar(); |
3. 基于Oracle简介
对于Oracle的读取主要是把phpmydatagrid.class.php中与MySQL连接的函数修改为Oracle,本篇是通过sqlrelay进行的Oracle连接,当然也可以使用PHP自带的OCI8模块(效率有些低),修改后另存为phporadatagrid.class.php即可在其他程序(datagrid_for_oracle.php)中调用。
以上就是教大家PHP如何直接修改表内容DataGrid功能的全过程,还有对数据库的了解,希望本文对大家的学习有所帮助。