由于需要連接Oracle所以從二次開發(fā)和頁面樣式來說個(gè)人覺得phpMyDataGrid還是比較好上手。
1. 創(chuàng)建測(cè)試數(shù)據(jù)庫和表
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
create database `guru`; USE `guru`; CREATE TABLE `employees` ( `id` int (6) NOT NULL auto_increment, ` name ` char (20) default NULL , `lastname` char (20) default NULL , `salary` float default NULL , `age` int (2) default NULL , `afiliation` date default NULL , `status` int (1) default NULL , `active` tinyint(1) default NULL , `workeddays` int (2) default NULL , `photo` char (30) default NULL , PRIMARY KEY (`id`) ) insert into `employees` (`id`,` name `,`lastname`,`salary`,`age`,`afiliation`,`status`,`active`,`workeddays`,`photo`) values (1, 'Ana' , 'Trujillo' ,2000,45, '2005-05-13' ,1,1,10, '1.jpg' ); insert into `employees` (`id`,` name `,`lastname`,`salary`,`age`,`afiliation`,`status`,`active`,`workeddays`,`photo`) values (2, 'Jennifer' , 'Aniston' ,3500,23, '2004-10-22' ,1,0,0, '2.jpg' ); insert into `employees` (`id`,` name `,`lastname`,`salary`,`age`,`afiliation`,`status`,`active`,`workeddays`,`photo`) values (3, 'Michael' , 'Norman' ,1200,19, '2007-01-10' ,1,1,5, '3.jpg' ); insert into `employees` (`id`,` name `,`lastname`,`salary`,`age`,`afiliation`,`status`,`active`,`workeddays`,`photo`) values (4, 'Vanessa' , 'Black' ,6500,31, '2000-11-05' ,1,1,30, '4.jpg' ); insert into `employees` (`id`,` name `,`lastname`,`salary`,`age`,`afiliation`,`status`,`active`,`workeddays`,`photo`) values (5, 'Michael' , 'Strauss' ,3200,45, '2006-10-21' ,2,0,22, '5.jpg' ); insert into `employees` (`id`,` name `,`lastname`,`salary`,`age`,`afiliation`,`status`,`active`,`workeddays`,`photo`) values (6, 'William' , 'Brown' ,2300,21, '2001-03-10' ,3,1,10, '6.jpg' ); insert into `employees` (`id`,` name `,`lastname`,`salary`,`age`,`afiliation`,`status`,`active`,`workeddays`,`photo`) values (7, 'Lucca' , 'Normany' ,2800,36, '2006-10-02' ,3,1,20, '7.jpg' ); |
2. PHP程序介紹
phpMyDataGrid主要是通過phpmydatagrid.class.php,dgscripts.js來實(shí)現(xiàn)的,總共加起來不到100kB,又是一個(gè)小巧的軟件。對(duì)于這兩個(gè)文件就不多講了,感興趣的同學(xué)可以“打包帶走”回去慢慢品。主要介紹該軟件的使用方法,即實(shí)例 datagrid_for_mysql.php。先看一下頁面示意圖:
程序講解:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
<?php include ( "phpmydatagrid.class.php" ); $objGrid = new datagrid; $objGrid ->closeTags(true); $objGrid ->friendlyHTML(); $objGrid ->methodForm( "get" ); //連接數(shù)據(jù)庫 $objGrid ->conectadb( "127.0.0.1" , "root" , "root" , "guru" ); //加密字符串 $objGrid ->salt( "Myc0defor5tr0ng3r-Pro3EctiOn" ); $objGrid ->language( "en" ); //最后一列顯示的功能鍵,從左向右功能為“新增鍵”、“編輯鍵”、“刪除鍵”、“瀏覽鍵”。 $objGrid ->buttons(true,true,true,true); //修改數(shù)值時(shí)產(chǎn)生的Form名稱 $objGrid ->form( 'employee' , true); //可檢索列名 $objGrid ->searchby( "name,lastname" ); //需要讀取的表 $objGrid ->tabla( "employees" ); //索引值用于修改數(shù)據(jù) $objGrid ->keyfield( "id" ); //分頁顯示行數(shù) $objGrid ->datarows(20); //默認(rèn)排序方式 $objGrid ->orderby( "name" , "ASC" ); //顯示列設(shè)置,相關(guān)設(shè)置可參考phpmydatagrid.class.php $objGrid ->FormatColumn( "id" , "ID Employee" , 5, 5, 1, "50" , "center" , "integer" ); $objGrid ->FormatColumn( "name" , "Name" , 30, 30, 0, "150" , "left" ); $objGrid ->FormatColumn( "lastname" , "Last name" , 30, 30, 0, "150" , "left" ); $objGrid ->FormatColumn( "age" , "Age" , 5, 5, 0, "50" , "right" ); //自定義日期格式 $objGrid ->FormatColumn( "afiliation" , "Afiliation Date" , 10, 10, 0, "100" , "center" , "date:dmy:/" ); //編輯時(shí)可以自定義為<Select>模式 $objGrid ->FormatColumn( "status" , "Status" , 5, 5, 0, "60" , "left" , "select:1_Single:2_Married:3_Divorced" ); //編輯時(shí)可以自定義為<CheckBox>模式 $objGrid ->FormatColumn( "active" , "Active" , 2, 2, 0, "50" , "center" , "check:No:Yes" ); //自定義貨幣顯示形式 $objGrid ->FormatColumn( "salary" , "Salary" , 10, 10, 0, "90" , "right" , "money:€" ); //將數(shù)據(jù)以柱狀圖顯示 $objGrid ->FormatColumn( "workeddays" , "Work days" , 5, 2, 0, "50" , "right" , "chart:percent:val:31" ); $objGrid ->checkable(); $objGrid ->setHeader(); $objGrid ->ajax( 'silent' ); echo '<html> <head><title>PHPDataGrid</title></head> <body><div align= "center" ><br />'; //生成DataGrid $objGrid ->grid(); echo '</div></body></html>' ; //關(guān)閉數(shù)據(jù)庫連接 $objGrid ->desconectar(); ?> |
3. 基于Oracle簡(jiǎn)介
對(duì)于Oracle的讀取主要是把phpmydatagrid.class.php中與MySQL連接的函數(shù)修改為Oracle,本篇是通過sqlrelay進(jìn)行的Oracle連接,當(dāng)然也可以使用PHP自帶的OCI8模塊(效率有些低),修改后另存為phporadatagrid.class.php即可在其他程序(datagrid_for_oracle.php)中調(diào)用。
以上就是教大家PHP如何直接修改表內(nèi)容DataGrid功能的全過程,還有對(duì)數(shù)據(jù)庫的了解,希望本文對(duì)大家的學(xué)習(xí)有所幫助。