File: db_array.php

package info (click to toggle)
phpreports 0.4.7-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 664 kB
  • ctags: 1,362
  • sloc: php: 3,248; xml: 203; makefile: 29; sh: 17; python: 10
file content (71 lines) | stat: -rwxr-xr-x 1,628 bytes parent folder | download
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
	/*
	 * To use this interface you need an array on the format returned by
	 * some functions like oci_fetch_all, with indexes for the column names and
	 * arrays for each column value like this two column / five rows array:
	 * array("FIELD1"=>array(1,2,3,4,5),"FIELD2"=>array("one","two","three","four","five"))
	 *
	 * Example of use:
	 *
	*	$a = array(	"id"=>array(1,2,3,4,5),
	*					"name"=>array("one","two","three","four","five"),
	*					"email"=>array("1@one","2@two","3@three","4@four","5@five"));
	*
	*	$r = new PHPReportMaker();
	*	$r->setDatabaseInterface("array");
	*	$r->setDatabaseConnection($a);
	*	$r->setXML("test.xml");
	*	$r->run();
	*/
	class PHPReportsDBI {
		var $_array;
		var $_pos;
		var $_cols;
		var $_rows;
		var $_keys;

		function db_connect($array) {
			return true;
		}

		function db_select_db($sDatabase) {
		}

		function db_query($array,$sql) {
			$this->_array	= $array;
			$this->_keys	= array_keys($array);
			$this->_pos		= 0;
			$this->_cols	= sizeof($array);
			$this->_rows	= sizeof($array[$this->_keys[0]]);
			return $this->_array;
		}

		function db_colnum($oStmt) {
			return $this->_rows; 
		}

		function db_columnName($oStmt,$iPos) {
			return $this->_keys[$iPos-1];
		}
		
		function db_columnType($oStmt,$iPos) {
			return gettype($this->array[$this->_keys[$iPos]][0]);
		}

		function db_fetch($oStmt) {
			if($this->_pos>$this->_rows)
				return null;
			$a = array();
			foreach($this->_keys as $key)
				$a[$key] = $this->_array[$key][$this->_pos];
			$this->_pos++;
			return $a; 
		}

		function db_free($oStmt) {
		}

		function db_disconnect($oCon) {
		}
	}	
?>