Caro Visitante!

Registe-se no fórum ou faça login, para ter total acesso ao fórum.
forumjovem.com
Caro Visitante!

Registe-se no fórum ou faça login, para ter total acesso ao fórum.
forumjovem.com

Você não está conectado. Conecte-se ou registre-se

Ver o tópico anterior Ver o tópico seguinte Ir para baixo  Mensagem [Página 1 de 1]

#1
 eduubessa

eduubessa
Membro
Membro
Boas pessoal, eu neste momento estou a desenvolver um grande projeto e nao tenho tido muito tempo para aqui para o forum como tinha prometido. Mas sempre que tenho um bucadinho venho aqui nem que seja ler os tópicos.

Eu desta vez deixo aqui um código que usei para o projecto que estou a desenvolver neste momento:

Eu criei esta classe, que poderá também ser muito útil para vocês (pelo menos espero eu)
Código:

<?php

   $get = new systemGetModules;

   class systemDatabaseMySql {
   
      private    $stHost = "127.0.0.1";
      private     $stUser = "root";
      private      $stPass = "C!1kRzBtdFUP";
      private      $stName = "thecamerakids_database";

      private      $stMySqlConnection          = FALSE;
      public      $stMySqlTypeSelect          = NULL;
      public      $stMySqlTables               = NULL;
      public       $stProtectionHTML           = TRUE;
      public        $stProtectionInjection       = TRUE;

      /* Tables predefined */
      private     $_TABLE_MENU         =   "tbl_menu";
      private      $_TABLE_POST         =   "tbl_posts";
      
      
      public function __construct(){
         $this->stMySqlConnection = mysqli_connect($this->stHost, $this->stUser, $this->stPass, $this->stName) or die (mysqli_error($this->stMySqlConnection));
      }
      
      public function __destruct() {
         if($this->stMySqlConnection != FALSE):
            mysqli_close($this->stMySqlConnection);
         endif;      
      }
      
      public function systemMySqlQuery($a, $b = NULL){
         if($a != NULL):
            $stMySqlQuery = $this->stMySqlConnection->query($a);
            if($b == "types"):
               $this->stMySqlTypeSelect = $stMySqlQuery;
            endif;
         endif;
      }
      
      public function systemMySqlSelectType($a = NULL){
         switch($a):
            case("rows")    : return mysqli_num_rows($this->stMySqlTypeSelect);    break;
            case("array")    : return mysqli_fetch_array($this->stMySqlTypeSelect);  break;
            case("assoc")    : return mysqli_fetch_assoc($this->stMySqlTypeSelect);  break;
            case("object")    : return mysqli_fetch_object($this->stMySqlTypeSelect); break;
            default          : return mysqli_fetch_object($this->stMySqlTypeSelect); break;
         endswitch;
      }
      
      public function systemMySqlInsertData($a)
      {
         $x = array();
         $y = array();
         
         for($i = 0; $i < count($a); $i++):
            foreach($a[$i] as $camp => $value):
               eval("\$x[" . $i . "] = '" . $camp . "'; \$y[" . $i ."] = '" . $value . "';");
            endforeach;
         endfor;
         
         $stMySqlInsertData = "INSERT INTO `" . $this->stMySqlTables . "` (";
         
         for($i = 0; $i < count($y); $i++):
            $stMySqlInsertData .= is_numeric($y[$i]) ? $y[$i] : "'" . $y[$i] . "'";
            if($i < count($y) - 1):
               $stMySqlInsertData .= ',';
            else:
               $stMySqlInsertData .= ");";
            endif;
         endfor;   
         
         return $this->systemMySqlQuery($stMySqlInsertData);   
      }
      
      public function systemMySqlUpdateData($a, $b, $c){
         $x = array();
         $y = array();
         
         for($i = 0; $i < count($a); $i++):
            foreach($a[$i] as $camp => $value):
               eval("\$x[" . $i . "] = '" . $camp . "'; \$y[" . $i ."] = '" . $value . "';");
            endforeach;
         endfor;
         
         $stMySqlUpdateData = "UPDATE `" . $this->stMySqlTables . "` SET ";
         
         for($i = 0; $i < count($y); $i++):
            $stMySqlInsertData .= is_numeric($y[$i]) ? $y[$i] : "'" . $y[$i] . "'";
            if($i < count($y) - 1):
               $stMySqlInsertData .= ',';
            endif;
         endfor;   
         
         $stMySqlUpdateData .= "WHERE `" . $b . "` LIKE '" . $c . "';";
         
         return $this->systemMySqlQuery($stMySqlUpdateData);
      }
      
      public function systemMySqlDeleteData($a, $b){
         $stMySqlDeleteData = "DELETE FROM `" . $this->stMySqlTables . "` WHERE `" . $a . "` LIKE '" . $b . "'";
         
         return $this->systemMySqlQuery($stMySqlDeleteData);
      }
      
      public function systemMySqlSelectData($a, $b){
         $stMySqlSelectData = "SELECT * FROM `" . $this->stMySqlTables . "`";
         
         if($a != NULL):
            $stMySqlSelectData .= "WHERE " . $a;
         elseif($b != NULL):
            $stMySqlSelectData .= " " . $b;
         endif;
         
         return $this->systemMySqlQuery($stMySqlSelectData, "types");
      }
      
      public function systemMySqlSelectDataJoin($a, $r, $l){
         
         $stMySqlSelectJoinData = "SELECT * FROM `" . $this->stMySqlTables . "` INNER JOIN ";
         
         $w = count($a);
         foreach($a as $b => $c):
            $w--;
            $stMySqlSelectJoinData .= "`" . $b . "` ON `" . $this->stMySqlTables . "`.`" . $c . "`=`" . $b . "`.`" . $c . "`";
            
            if($w != 0):
               $stMySqlSelectJoinData .= " <br />INNER JOIN ";
            else:
               if($r !== NULL):
                  $stMySqlSelectJoinData .= " WHERE " . $r;
               else:
                  $stMySqlSelectJoinData .= " " . $l;
               endif;
            endif;
         endforeach;
         
         $stMySqlSelectJoinData .= ";";
         
         return $this->systemMySqlQuery($stMySqlSelectJoinData, "types");
      }

      /* Get General Information in base de dados */
      public function menu($a){
         try{
            
            $this->stMySqlTables = "tbl_menu";
            $this->systemMySqlSelectData("(`menuCategory`='main') AND (`menuShow`='1');", NULL);

            if($this->systemMySqlSelectType("rows") > 0):
               echo("<ul>");
               while($menu = $this->systemMySqlSelectType("object")):
                  echo("<li onClick=\" ". $menu->menuLink ." \">" . $menu->menuText . "</li>");
               endwhile;
               echo("</ul>");               
            else:
               echo("Não está a dar!");
               exit;
            endif;

         }catch(\Exception $e){
            @self::__messageError($e->getMessage());
         }
      }

      public function gallery(){

         $a = "slider";
         $b = "";

         if($a == "video"):
            $b .= "<div class=\"__initialize_video\">
                      <video autoplay=\"true\" loop=\"true\" width=\"1924px\" height=\"350px\">
                         <source src=\"./__sysFiles/___sysGallery/video1.mp4\" type=\"video/mp4\" />
                      </video>
                  </div>
                 ";

         else:
            $b .= "<div class=\"__initialize_slider\">
                     <div class=\"jqSliderBox\">
                           <div class=\"jqSliderLoadElements\"></div>
                           <div class=\"jqSliderReady\">
                              <div class=\"jqSliderImgHref\"></div>
                              <div class=\"jqSliderBoxMaxImages\"></div>
                              <div class=\"jqSliderBoxImgsArrowLeft\" onClick=\"jqSliderBack()\"></div>
                              <div class=\"jqSliderBoxImgsArrowRight\" onClick=\"jqSliderNext()\"></div>
                              <div class=\"jqSliderBoxImgs\">
                                  <img src=\"./__sysFiles/___sysGallery/1.jpg\" id=\"1\" jqSliderTitle=\"Paisagem\"    jqSliderConcent=\"Paisagem representativa de uma ilha.\" jqSliderImageLink=\"\" />
                                  <img src=\"./__sysFiles/___sysGallery/2.jpg\" id=\"2\" jqSliderTitle=\"Guerra\"       jqSliderConcent=\"É um prato que se serve frio!\"        jqSliderImageLink=\"\" />
                              <img src=\"./__sysFiles/___sysGallery/3.jpg\" id=\"3\" jqSliderTitle=\"Guerra\"       jqSliderConcent=\"É um prato que se serve frio!\"        jqSliderImageLink=\"\" />
                              <img src=\"./__sysFiles/___sysGallery/4.jpg\" id=\"4\" jqSliderTitle=\"Guerra\"       jqSliderConcent=\"É um prato que se serve frio!\"        jqSliderImageLink=\"\" />
                              </div>
                              <div class=\"jqSliderBoxInfos\">
                                   <div class=\"jqSliderBoxInfosTitle\"></div>
                                 <div class=\"jqSliderBoxInfosConcent\"></div>
                              </div>
                             <div class=\"jqSliderBoxTimeOfNextImage\"><div></div></div>
                          </div>
                      </div>
                  </div>
                 ";
         endif;

         echo($b);
      }

      public function posts($a){

         try{
            $this->stMySqlTables = "tbl_posts";
            $this->systemMySqlSelectData("(`categorieId`='" . $a ."')", NULL);

            if($this->systemMySqlSelectType("rows") > 0):
               while($post = $this->systemMySqlSelectType("object")):
                  echo $post->postContent;
               endwhile;         
            else:
               echo("Não está a dar!");
               exit;
            endif;

         }catch(\Exception $e){
            @self::__messageError($e->getMessage());
         }
      }
      
      
      public function categories($a){
         $this->stMySqlTables = "tbl_categories";
         $this->systemMySqlSelectData("(`categoryLocal`='" . $a . "')", "LIMIT 4");
         
         if($this->systemMySqlSelectType("rows") > 0):
            $i = 0;
            while($category = $this->systemMySqlSelectType("object")):
               $i++;
               if($i == 1):
                  echo '<li class="active" data-section-tab="' . $i . '">' . $category->categoryName . '</li>';
               else:
                  echo '<li data-section-tab="' . $i . '">' . $category->categoryName . '</li>';
               endif;
            endwhile;         
         else:
            echo("Não está a dar!");
            exit;
         endif;
      }
      
      public function gallery_home($a = null){
         $this->stMySqlTables = "tbl_photos";
         $b = array("tbl_accounts" => "accountId");
         $this->systemMySqlSelectDataJoin($b, "(`photoCategory` LIKE '" . $a . "') LIMIT 19 ", null);
         
         if($this->systemMySqlSelectType("rows") > 0):
            while($x = $this->systemMySqlSelectType("object")):
               $y = './__sysFiles/___sysUsers/' . $x->accountFolder . '/____portfolio/' . $x->photoFilename;
               if(file_exists($y)):
                  echo('<img class="__photo" src="' . $y . '" />');
               
               endif;
            endwhile;
         endif;
      }

   }

?>

Nas ultimas funções já é funções a utilizar o mesmo, espero ter ajudado muitos

#2
 chino

chino
Membro
Membro
Muito bem , gostei.
Uma coisa tens aulas de programação ?

#3
 eduubessa

eduubessa
Membro
Membro
Agora nao !, mas tive 3 anos no curso de informática de gestão onde dei bastante pouco de PHP!

[Edit]
Agora estou a desenvolver isso para JAVA
[/Edit]

#4
 chino

chino
Membro
Membro
eduubessa escreveu:Agora nao !, mas tive 3 anos no curso de informática de gestão onde dei bastante pouco de PHP!

[Edit]
Agora estou a desenvolver isso para JAVA
[/Edit]

Usas algum programa especifico

#5
 eduubessa

eduubessa
Membro
Membro
Depende do que vou programar

#6
 João Gouveia ☩

João Gouveia ☩
Membro
Membro
onde colar ?

#7
 Conteúdo patrocinado


Ver o tópico anterior Ver o tópico seguinte Ir para o topo  Mensagem [Página 1 de 1]


Permissões neste sub-fórum
Não podes responder a tópicos