<?\\ This code is licenced over GPLv2.include ("config.php");class database{ function database ( $sgdb ) { function checkQuotation ($string) { if ( ereg ("\'", $string) | ereg ("\"", $string) ) { die (1); } else return (0); } if ($sgdb == "mysql") { //Initialize the database include ("mysql_params.php"); $connect = mysql_connect ($dbsever, $dbuser, $dbpasswd) or die ('Impossivel conectar ao banco de dados. Erro: ' . mysql_error()); mysql_select_db($database, $connect); // For now a little POG function insertData ($table, $dataarray) /* Documentation: This function is part of the data access framework and inserts data into the database in a common syntax. Their return codes are: * 0: Success * 1: ' and " inserted into $dataarray, to prevent a explosion on the database */ { $i = 0; $insert = "INSERT INTO $table VALUES ("; foreach ($dataarray as $value) { // Checking if have no "'" or """ into the array and die if have checkQuotation ($alue); $i++; $insert .= "'$value'"; if ($i != sizeof ($dataarray)) {$insert .= ", ";} if ($i == sizeof ($dataarray)) {$insert .= ")";} if ($i == sizeof ($dataarray)) {$insert .= ";";} } mysql_query($insert) or die ("Ocorreu um erro na entrada de dados: " . mysql_error()); //echo "$insert"; } function getValuesMatch ($table, $whatever_to_get="NONE" ) { if ($whatever_to_get == "none") { $getdata = "SELECT * from $table"; } else { $i = 0; $getdata = "(SELECT * FROM `$table` WHERE "; foreach ($whatever_to_get as $key => $value) { checkQuotation ($value); checkQuotation ($key); $i++; // Ive been helped to build this and im thankfull all Free Software people, and from scorphus and guaxinin from #debian-br@freenode if (is_array($value)) { $i=0; foreach ($value as $key_int => $value_int) { $i++; //Very thankfull to scorphus@#debian-br@freenode $getdata .= " $key like '$value_int' "; if ($i == sizeof ($value_int)) {$getdata .= " OR ";} } $getdata .= " );"; } else { $getdata .= "$key like '$value'"; if ($i != sizeof ($whatever_to_get)) {$getdata .= ", ";} if ($i == sizeof ($whatever_to_get)) {$getdata .= ")";} if ($i == sizeof ($whatever_to_get)) {$getdata .= ";";} } } } $retorno = mysql_query($getdata) or die ("Ocorreu um erro no requerimento de dados: ". mysql_error()); //return ($retorno); //echo ($getdata); // Another scorphus suggestion - Thanks! while ($row_temp = mysql_fetch_array($retorno)) { $return_array[] = $row_temp; } return ($return_array); } function Destroy () { mysql_close($connect); } } elseif ($sgbd == "pgsql") { //include pgsql_params.php // $connect = pgsql function insertdata ($table, $dataarray) { } } }}?>