Recently, I want to implement the DataGrid function using PHP, so that I can directly modify the table content in the database without developing the [add data page] and [Edit page ], as a result, I found several similar items on the Internet, including open-source and paid items, but they are basically based on MySQL. Because you need to connect to Oracle, from the secondary development and page style, I personally think phpMyDataGrid is better to use. This article first introduces how to use MySQL, and then briefly introduces the secondary development of Oracle connection (based on sqlrelay.
1. Create a test database and table
- 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 program Introduction
PhpMyDataGrid is mainly implemented through phpmydatagrid. class. php and dgscripts. js. The total size is less than kb, and it is a small software. I will not talk about these two files much. If you are interested, you can "pack and take it" back to the product. This section describes how to use the software, that is, the instance datagrid_for_mysql.php. Let's take a look at the page:
498) this. width = 498; 'onmousewheel = 'javascript: return big (this) 'title = "2009-8-11-19.22.06" style = "border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px "height =" 270 "alt =" 2009-8-11-19.22.06 "src =" http://www.bkjia.com/uploadfile/2013/0904/20130904095417528.jpg "width =" 980 "border =" 0 "/>
Program description:
- <? Php
- Include ("phpmydatagrid. class. php ");
- $ ObjGrid = new datagrid;
- $ ObjGrid-> closeTags (true );
- $ ObjGrid-> friendlyHTML ();
- $ ObjGrid-> methodForm ("get ");
- // Connect to the database
- $ ObjGrid-> conectadb ("127.0.0.1", "root", "root", "guru"); // encrypted string
- $ ObjGrid-> salt ("Myc0defor5tr0ng3r-Pro3EctiOn ");
- $ ObjGrid-> language ("en ");
- // The function key displayed in the last column. The options include "add key", "Edit key", "delete key", and "Browse key ".
- $ ObjGrid-> buttons (true, true );
- // Modify the Form name generated by the numeric value
- $ ObjGrid-> form ('Employee', true );
- // Searchable column name
- $ ObjGrid-> searchby ("name, lastname ");
- // The table to be read
- $ ObjGrid-> tabla ("employees ");
- // The index value is used to modify data.
- $ ObjGrid-> keyfield ("id ");
- // Number of lines displayed by PAGE
- $ ObjGrid-> datarows (20 );
- // Default sorting method
- $ ObjGrid-> orderby ("name", "ASC ");
- // Display column settings. For more information, see 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"); // custom Date Format
- $ ObjGrid-> FormatColumn ("afiliation", "Afiliation Date", 10, 10, 0, "100", "center", "date: dmy :/"); // The <Select> mode can be customized during editing.
- $ ObjGrid-> FormatColumn ("status", "Status", 5, 5, 0, "60", "left", "select: distinct single: 2_Married: 3_Divorced ");
- // The <CheckBox> mode can be customized during editing.
- $ ObjGrid-> FormatColumn ("active", "Active", 2, 2, 0, "50", "center", "check: No: Yes "); // display the custom currency
- $ ObjGrid-> FormatColumn ("salary", "Salary", 10, 10, 0, "90", "right", "money: & euro ;"); // display data in a column chart
- $ ObjGrid-> FormatColumn ("workeddays", "Work days", 5, 2, 0, "50", "right", "chart: percent: val: 31 ");
- $ ObjGrid-> checkable ();
- $ ObjGrid-> setHeader ();
- $ ObjGrid-> ajax ('silent ');
- Echo '
- <Head> <title> PHPDataGrid </title>
- <Body> <div align = "center"> <br/> ';
- // Generate the DataGrid
- $ ObjGrid-> grid ();
- Echo '</div> </body>
- $ ObjGrid-> desconectar ();
- ?>
3. Oracle-based introduction
For Oracle reading, the function connecting phpmydatagrid. class. php to MySQL is changed to Oracle. This article uses sqlrelay (see