11<?php
2-
32/*
43Copyright (c) 2007, Till Brehm, projektfarm Gmbh
54All rights reserved.
@@ -33,11 +32,11 @@ class db {
3332 private $ dbName = '' ; // logical database name on that server
3433 private $ dbUser = '' ; // database authorized user
3534 private $ dbPass = '' ; // user's password
36- private $ dbCharset = "" ; // what charset comes and goes to mysql: utf8 / latin1
35+ private $ dbCharset = '' ; // what charset comes and goes to mysql: utf8 / latin1
3736 private $ linkId = 0 ; // last result of mysql_connect()
3837 private $ queryId = 0 ; // last result of mysql_query()
3938 private $ record = array (); // last record fetched
40- private $ autoCommit = 1 ; // Autocommit Transactions
39+ private $ autoCommit = 1 ; // Autocommit Transactions
4140 private $ currentRow ; // current row number
4241 private $ errorNumber = 0 ; // last error number
4342 public $ errorMessage = '' ; // last error message
@@ -68,7 +67,7 @@ public function updateError($location)
6867 }
6968
7069 public function connect ()
71- {
70+ {
7271 if ($ this ->linkId == 0 ){
7372 $ this ->linkId = mysql_connect ($ this ->dbHost , $ this ->dbUser , $ this ->dbPass );
7473 if (!$ this ->linkId ){
@@ -82,7 +81,7 @@ public function connect()
8281 }
8382
8483 public function query ($ queryString )
85- {
84+ {
8685 if (!$ this ->connect ()){
8786 return false ;
8887 }
@@ -101,7 +100,7 @@ public function query($queryString)
101100
102101 /** Returns all records as an array */
103102 public function queryAllRecords ($ queryString )
104- {
103+ {
105104 if (!$ this ->query ($ queryString )){
106105 return false ;
107106 }
@@ -114,7 +113,7 @@ public function queryAllRecords($queryString)
114113
115114 /** Returns one row as an array */
116115 public function queryOneRecord ($ queryString )
117- {
116+ {
118117 if (!$ this ->query ($ queryString ) || $ this ->numRows () == 0 ){
119118 return false ;
120119 }
@@ -123,8 +122,8 @@ public function queryOneRecord($queryString)
123122
124123 /** Returns the next record as an array */
125124 public function nextRecord ()
126- {
127- $ this ->record = mysql_fetch_assoc ($ this ->queryId );
125+ {
126+ $ this ->record = mysql_fetch_assoc ($ this ->queryId );
128127 $ this ->updateError ('DB::nextRecord()<br />mysql_fetch_array ' );
129128 if (!$ this ->record || !is_array ($ this ->record )){
130129 return false ;
@@ -146,7 +145,7 @@ public function affectedRows()
146145
147146 /** Returns the last mySQL insert_id() */
148147 public function insertID ()
149- {
148+ {
150149 return mysql_insert_id ($ this ->linkId );
151150 }
152151
@@ -217,7 +216,7 @@ public function update($tablename, $form, $bedingung, $debug = 0)
217216 }
218217 }
219218 */
220-
219+
221220 public function diffrec ($ record_old , $ record_new ) {
222221 $ diffrec_full = array ();
223222 $ diff_num = 0 ;
@@ -270,16 +269,16 @@ public function datalogSave($db_table, $action, $primary_field, $primary_id, $re
270269 unset($ tmp );
271270
272271 // Insert the server_id, if the record has a server_id
273- $ server_id = (isset ($ record_old [" server_id " ]) && $ record_old [" server_id " ] > 0 )?$ record_old [" server_id " ]:0 ;
274- if (isset ($ record_new [" server_id " ])) $ server_id = $ record_new [" server_id " ];
272+ $ server_id = (isset ($ record_old [' server_id ' ]) && $ record_old [' server_id ' ] > 0 )?$ record_old [' server_id ' ]:0 ;
273+ if (isset ($ record_new [' server_id ' ])) $ server_id = $ record_new [' server_id ' ];
275274
276275
277276 if ($ diff_num > 0 ) {
278277 //print_r($diff_num);
279278 //print_r($diffrec_full);
280279 $ diffstr = $ app ->db ->quote (serialize ($ diffrec_full ));
281- $ username = $ app ->db ->quote ($ _SESSION [" s " ][ " user " ][ " username " ]);
282- $ dbidx = $ primary_field ." : " .$ primary_id ;
280+ $ username = $ app ->db ->quote ($ _SESSION [' s ' ][ ' user ' ][ ' username ' ]);
281+ $ dbidx = $ primary_field .' : ' .$ primary_id ;
283282
284283 if ($ action == 'INSERT ' ) $ action = 'i ' ;
285284 if ($ action == 'UPDATE ' ) $ action = 'u ' ;
@@ -327,8 +326,8 @@ public function datalogDelete($tablename, $index_field, $index_value) {
327326
328327 return true ;
329328 }
330-
331-
329+
330+
332331
333332 public function closeConn ()
334333 {
@@ -338,7 +337,7 @@ public function closeConn()
338337 return true ;
339338 } else { return false ; }
340339 }
341-
340+
342341 public function freeResult ($ query )
343342 {
344343 if (mysql_free_result ($ query ))
@@ -406,10 +405,10 @@ public function createTable($table_name, $columns)
406405 if (isset ($ col ['option ' ]) && $ col ['option ' ] == 'primary ' ){ $ index .= 'PRIMARY KEY ( ' .$ col ['name ' ].'), ' ; }
407406 if (isset ($ col ['option ' ]) && $ col ['option ' ] == 'index ' ){ $ index .= 'INDEX ( ' .$ col ['name ' ].'), ' ; }
408407 if (isset ($ col ['option ' ]) && $ col ['option ' ] == 'unique ' ){ $ index .= 'UNIQUE ( ' .$ col ['name ' ].'), ' ; }
409- }
408+ }
410409 $ sql .= $ index ;
411410 $ sql = substr ($ sql ,0 ,-1 );
412- $ sql .= ') ' ;
411+ $ sql .= ') ' ;
413412 $ this ->query ($ sql );
414413 return true ;
415414 }
@@ -428,36 +427,36 @@ public function createTable($table_name, $columns)
428427 */
429428 public function alterTable ($ table_name ,$ columns )
430429 {
431- $ index = '' ;
432- $ sql = "ALTER TABLE $ table_name " ;
433- foreach ($ columns as $ col ){
430+ $ index = '' ;
431+ $ sql = "ALTER TABLE $ table_name " ;
432+ foreach ($ columns as $ col ){
434433 if ($ col ['action ' ] == 'add ' ){
435- $ sql .= 'ADD ' .$ col ['name ' ].' ' .$ this ->mapType ($ col ['type ' ], $ col ['typeValue ' ]).' ' ;
434+ $ sql .= 'ADD ' .$ col ['name ' ].' ' .$ this ->mapType ($ col ['type ' ],$ col ['typeValue ' ]).' ' ;
436435 }elseif ($ col ['action ' ] == 'alter ' ) {
437436 $ sql .= 'CHANGE ' .$ col ['name ' ].' ' .$ col ['name_new ' ].' ' .$ this ->mapType ($ col ['type ' ],$ col ['typeValue ' ]).' ' ;
438437 }elseif ($ col ['action ' ] == 'drop ' ) {
439438 $ sql .= 'DROP ' .$ col ['name ' ].' ' ;
440439 }
441- if ($ col [" action " ] != 'drop ' ) {
442- if ($ col [" defaultValue " ] != "" ) $ sql .= "DEFAULT ' " .$ col [" defaultValue " ]."' " ;
443- if ($ col [" notNull " ] == true ) {
444- $ sql .= " NOT NULL " ;
440+ if ($ col [' action ' ] != 'drop ' ) {
441+ if ($ col [' defaultValue ' ] != '' ) $ sql .= "DEFAULT ' " .$ col [' defaultValue ' ]."' " ;
442+ if ($ col [' notNull ' ] == true ) {
443+ $ sql .= ' NOT NULL ' ;
445444 } else {
446- $ sql .= " NULL " ;
445+ $ sql .= ' NULL ' ;
447446 }
448- if ($ col [" autoInc " ] == true ) $ sql .= " auto_increment " ;
449- $ sql .= " , " ;
447+ if ($ col [' autoInc ' ] == true ) $ sql .= ' auto_increment ' ;
448+ $ sql .= ' , ' ;
450449 //* Index definitions
451450 if ($ col ['option ' ] == 'primary ' ) $ index .= 'PRIMARY KEY ( ' .$ col ['name ' ].'), ' ;
452451 if ($ col ['option ' ] == 'index ' ) $ index .= 'INDEX ( ' .$ col ['name ' ].'), ' ;
453452 if ($ col ['option ' ] == 'unique ' ) $ index .= 'UNIQUE ( ' .$ col ['name ' ].'), ' ;
454453 }
455- }
456- $ sql .= $ index ;
457- $ sql = substr ($ sql ,0 ,-1 );
458- //die($sql);
459- $ this ->query ($ sql );
460- return true ;
454+ }
455+ $ sql .= $ index ;
456+ $ sql = substr ($ sql ,0 ,-1 );
457+ //die($sql);
458+ $ this ->query ($ sql );
459+ return true ;
461460 }
462461
463462 public function dropTable ($ table_name )
@@ -484,7 +483,7 @@ public function getTables($database_name = '')
484483
485484 public function tableInfo ($ table_name ) {
486485 //* Tabellenfelder einlesen ?
487- if ($ rows = $ this ->queryAllRecords (" SHOW FIELDS FROM $ table_name" )){
486+ if ($ rows = $ this ->queryAllRecords (' SHOW FIELDS FROM $table_name ' )){
488487 foreach ($ rows as $ row ) {
489488 $ name = $ row ['Field ' ];
490489 $ default = $ row ['Default ' ];
@@ -512,9 +511,9 @@ public function tableInfo($table_name) {
512511 $ tmp_typeValue = explode ('( ' ,$ type );
513512 $ column ['typeValue ' ] = substr ($ tmp_typeValue [1 ], 0 , -1 );
514513 }
515- if (stristr ($ type , 'text ' )) $ metaType = 'text ' ;
516- if (stristr ($ type , 'double ' )) $ metaType = 'double ' ;
517- if (stristr ($ type , 'blob ' )) $ metaType = 'blob ' ;
514+ if (stristr ($ type ,'text ' )) $ metaType = 'text ' ;
515+ if (stristr ($ type ,'double ' )) $ metaType = 'double ' ;
516+ if (stristr ($ type ,'blob ' )) $ metaType = 'blob ' ;
518517
519518 $ column ['type ' ] = $ metaType ;
520519 $ columns [] = $ column ;
@@ -548,7 +547,7 @@ public function mapType($metaType, $typeValue) {
548547 return 'blob ' ;
549548 }
550549 }
551-
550+
552551}
553552
554- ?>
553+ ?>
0 commit comments