Recommend this page to a friend! |
All PHP | > | All threads | > | translation | > | (Un) Subscribe thread alerts |
|
juglesh - 2008-06-12 15:23:31
<?PHP
/** * Class allPHP v2.0 * Author: Angelo Vicente Filho * Data: 22/05/2008 * Functions para manipulação de DB * Arquivo: class.allphp.php **/ include "config.php"; $checkurl = $_SERVER['PHP_SELF']; if (eregi('class.allphp.php',$checkurl)) { die("You do not have permission to access this file!"); } class allPHP{ var $porPagina = QTD; var $get; // function to connect to the database // receives a string as a parameter function conecta($sql){ $conexao = mysql_connect(HOST,USER,PASS) or die ("Erro ao conectar ao Banco de Dados."); $db = mysql_select_db(BANCO,$conexao); $result = mysql_query($sql,$conexao); mysql_close($conexao); return $result; } // function to perform simple queries in the database. // receives two parameters, the table affected and how you want // Order function sqlSelect($table,$order){ $sql = "SELECT * FROM ".$table." ORDER BY ".$order.""; $result = @$this->conecta($sql); return $result; } // function to select a record in a given table // receives 3 parameters // @ name table, @ idTable, @ id function sqlSelectUnico($table,$idTable,$id){ $sql = "SELECT * FROM ".$table." WHERE ".$idTable. " = ".$id; $result = $this->conecta($sql); return $result; } // function to perform insertions in only one table, // 3 paramentros receives, the name of the table affected, with a vector // data to be entered and a vector with the affected fields in the table. function sqlInsert($table,$vetDados,$vetCampos){ $into = ""; $value = ""; $virgula = ""; for($I = 0; $I < sizeof($vetDados); $I++){ $into .= $virgula.$vetCampos[$I]; $value .= $virgula."'".$vetDados[$I]."'"; $virgula = ","; } $insert = "INSERT INTO ".$table."(".$into.") values (".$value.")"; $this->conecta($insert); } // function to perform updates in only one table, // receives 5 paramentros function sqlUpdate($table,$vetDados,$vetCampos,$cmpId,$id){ $set = ""; $value = ""; $virgula = ""; for($I = 0; $I < sizeof($vetDados); $I++){ $set .= $virgula.$vetCampos[$I]."= '".$vetDados[$I]."'"; $virgula = ","; } $up = "UPDATE ".$table." SET ".$set." WHERE ".$cmpId. " = '".$id."'"; $this->conecta($up); } // function that makes consula on 2 tables // receives as a parameter tables and the id's to cross // everything in a vector function sqlSelect2Table($vetorTable,$umRegistro){ if(!$umRegistro){ $select = "SELECT * FROM ".$vetorTable['table1'].",".$vetorTable['table2']." WHERE ".$vetorTable['table1'].".".$vetorTable['idTable1']." = ".$vetorTable['table2'].".".$vetorTable['idTable2'].""; } if($umRegistro){ $select = "SELECT DISTINCT * FROM ".$vetorTable['table1'].",".$vetorTable['table2']." WHERE ".$vetorTable['table1'].".".$vetorTable['idTable1']." = ".$vetorTable['table2'].".".$vetorTable['idTable2']." AND ".$vetorTable['table2'].".".$vetorTable['idIndexTable2']." = '".$vetorTable['valorIndex']."' "; } $result = $this->conecta($select); return $result; } // function to catch the last issue on the table id function sqlUltimoId($table,$id){ $sql = "SELECT * FROM ".$table. " ORDER BY ".$id." DESC LIMIT 1"; $result = $this->conecta($sql); return $result; } // function to select in a single table // but using a filter function sqlFiltro($table,$idTable,$id){ $sql = "SELECT * FROM ".$table." WHERE ".$idTable. " = '".$id."'"; $rs = $this->conecta($sql); return $rs; } // funcoa to deleter a record in a table // receives three paramentros // @ table, @ idTable, @ id function sqlDelete($table,$idTable,$id){ $del = "DELETE FROM ".$table." WHERE ".$idTable. " = ".$id; $this->conecta($del); } // function to return the amount of lines of a record // receives an SQL statement as a parameter string // @ query function sqlLinas($query="") { $consulta = !empty($query) ? $query: $this->sql; $linhas = @mysql_num_rows($consulta); return $linhas; } // Function for setar the objects of MySQL // Receive SQL statement as a string of parameter // @ consultation function sqlFetchObject($consulta = "") { $consulta = !empty($consulta) ? $consulta : $this->sql; $obj = @mysql_fetch_object($consulta); return $obj; } // Function for setar an array of basic MySQL // Receive a SQL statement as a parameter String // @ consultation function sqlFetchArray($consulta="") { $consulta = !empty($consulta) ? $consulta : $this->sql; $arr = @mysql_fetch_array($consulta); return $arr; } // Function for manipulation of paging // Reference the amount of record per page function porPagina() { $this->get = @$_GET["porPagina"]; if( $this->get == "" OR $this->get == 0) { return $this->porPagina; } else { return $this->get; } } // Function to show the page that is the pagination function pagina() { $this->get = @$_GET["pagina"]; if ($this->get == ""){ return (int)1; } else { return $this->get; } } // Function that shows the record for page layout of the results function pRegistro() { return ($this->pagina()*$this->porPagina()) - $this->porPagina(); } // Function which is the counting of number of pages exist for total resistro // Receive a whole number as a parameter // @ totalRegistro function tPagina($totalRegistro) { return ceil($totalRegistro/$this->porPagina()); } // Function for the submission of the paging links "Previous [1] [2] [3] Last ' // Receive a whole number as a parameter] // @ totalRegistro function pNavegacao($totalRegistro) { global $PHP_SELF; if($this->pagina() > 1) { $anterior = $this->pagina() - 1; $link_ant = "<a href=\"$PHP_SELF?pagina=$anterior&porPagina=".$this->porPagina()."\">Anterior</a>"; } if($this->tPagina($totalRegistro) > $this->pagina()) { $proximo = $this->pagina() + 1; $link_pro = "<a href=\"$PHP_SELF?pagina=$proximo&porPagina=".$this->porPagina()."\">Proximo</a>"; } for ($x=1; $x <$this->tPagina($totalRegistro); $x++) { if ($x == $this->pagina()) { @$painel .= "[ $x ]"; } else { @$painel .= "<a href=\"$PHP_SELF?pagina=$x&porPagina=".$this->porPagina()."\">[$x]</a>"; } } if ($x <= $this->pagina()){ return ""; } else { return " ".@$link_ant." $painel ".@$link_pro."<br>"; } } // Function that builds the date in full function Data() { $arr = array("Domingo", "Segunda-feira", "Terça-feira", "Quarta-feira", "Quinta-feira", "Sexta-feira", "Sábado"); $semana = $arr[date("w")]; $arr = array("Janeiro", "Fevereiro", "Março", "Abril", "Maio", "Junho", "Julho", "Agosto", "Setembro", "Outubro", "Novembro", "Dezembro"); $mes = $arr[date("n") - 1]; $dataExtenso = $semana .", ". date("j")." de ". $mes ." de ". date("Y")."."; return $dataExtenso; } // Function of the message box // Receive two parameters String, The message and the destination after the ok // @ msg, @ dest function msgbox($msg="", $dest=""){ $alert = "<script>alert('".$msg."'); document.location.href='".$dest."'</script>"; return $alert; } // Function that creates a message box, and then opens a new window // Receive three parâmetos as String, The message of the box, the destination and the name of the popup window // @ msg, des @, @ name function janela($msg,$des,$nome) { $alert1 = "<script>alert('".$msg."');</script>"; $alert2 = "<script>window.open('".$des."','".$nome."');</script>"; $alert = $alert1." ".$alert2; return $alert; } // Function to redirect without any message // Receive a measure of String // dest @ function retor($dest=""){ $dest = "<script>document.location.href='".$dest."'</script>"; return $dest; } // Function for setar the field Main form // Receive two parameters string // @ nomeForm, @ nomeCampo function setarForm($nomeForm = "",$nomeCampo) { $setar = "javascript:document.".$nomeForm.".".$nomeCampo.".focus();"; return $setar; } // Function to transform the point at comma // Receive a String parameter or Int // @ Value function cPonto($Valor){ $tmpValor = explode(".",$Valor); $Valor = implode(",",$tmpValor); return $Valor; } // Function to transform the point in vírguma // Receive a String parameter or Int // @ mValor function cVirgula($mValor){ $tmpValor = explode(",",$mValor); $mValor = implode(".",$tmpValor); return $mValor; } // Function to transform a date mm / dd / yyyy in yyyy-mm-dd // Receive a parameter Date // @ mData function cData($mData){ $tmpData = explode("/",$mData); $mData = implode("-",array_reverse($tmpData)); return $mData; } // Function to transform a date yyyy-mm-dd in mm / dd / yyyy // Receive a parameter Date // @ mData function vData($mData){ $tempData = explode("-",$mData); $restData = implode("/",array_reverse($tempData)); return $restData; } // Function that transformat Float in a number Real Ex: 1.5 to 1.50 // Function receives a parameter in Float // @ v function vReal($v) { $vRealFormat = number_format($v,2,',','.'); return $vRealFormat; } } ?> |
info at phpclasses dot org
.