Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Salve Galera!!
To começando e estruturar um projeto com PHP e OOP e estou tendo algumas dificuldades, gostaria se possivel uma ajuda.
Hoje estruturo meus objetos da forma abaixo:
<?phpclass consulta{ var $celular = array("9", "8", "7"); var $arquivo = " "; var $telefone = " "; var $host = "localhost"; var $user = "root"; var $pass = ""; var $db = "meudatabase"; var $q = ""; var $r = ""; var $reg = ""; var $aberto; var $linha = " "; var $nome = " "; var $c = 1; function consulta($arquivo = ""){ if($arquivo != ""){ $this->arquivo = $arquivo; } } function conexao($db){ if($db == "lista"){ mysql_connect($this->host, $this->user, $this->pass); mysql_select_db($this->db); } } #F2F2F2#EAEAEA function pesquisar($arquivo = ""){ if($arquivo != ""){ $this->conexao("lista"); $this->arquivo = $arquivo; $this->aberto = fopen($this->arquivo, "r"); echo " <p class='text'><b>Resultado da pesquisa:</b></p> <table border='1' width='100%'> <tr align='center' bgcolor='#EAEAEA' class='text' height='25' valign='middle'> <td><b>Nome</b></td> <td><b>Telefone</b></td> <td><b>Endereço</b></td> <td><b>Bairro</b></td> <td><b>CEP</b></td> <td><b>Cidade</b></td> <td><b>UF</b></td> </tr> "; while(!feof($this->aberto)){ $this->linha = fgets($this->aberto); list($this->nome, $this->telefone) = explode(";", $this->linha); $this->telefone = $this->preparar_telefone($this->telefone); if(!in_array(substr($this->telefone, 0, 1), $this->celular)){ $this->q = "SELECT * FROM ddd11 WHERE Telefone = '{$this->telefone}';"; $this->r = mysql_query($this->q); $this->reg = mysql_fetch_array($this->r); echo "<tr valign='middle' class='text' height='20' align='center' bgcolor='",(($this->c % 2 == 0 ) ? "#F2F2F2" : "#FFFFFF"),"'> <td class='text'>",$this->inicial_maiuscula($this->nome), "</td> <td class='text'>",$this->telefone, "</td> <td class='text' align='left'>",$this->inicial_maiuscula($this->reg['Endereco']), "</td> <td class='text'>",$this->inicial_maiuscula($this->reg['Bairro']), "</td> <td class='text'>",$this->cep_formatado($this->reg['CEP']), "</td> <td class='text'>",$this->reg['Cidade'], "</td> <td class='text'>",$this->reg['UF'], "</td> </tr>"; $this->c++; } } echo "</table>"; fclose($this->aberto); } } function inicial_maiuscula($texto){ return substr($texto,0,1).strtolower(substr($texto, 1, (strlen($texto) - 1))); } function preparar_telefone($telefone){ $telefone = str_replace("(11)", "", $telefone); $telefone = str_replace("-", "", $telefone); $telefone = str_replace(".", "", $telefone); $telefone = str_replace("/", "", $telefone); $telefone = str_replace("(", "", $telefone); $telefone = str_replace(")", "", $telefone); return $telefone; } function cep_formatado($cep = ""){ if($cep != ""){ return substr($cep, 0, 5)."-".substr($cep, 5, 3); } }}#end class;?>
Queria saber se está errado ? O que isso influencia na performace ? Como criar objetos mais diretos e objetivos ? Como programar para funcionar bem na versão 4 e 5 do PHP ?
[]s
Carregando comentários...