good practice in building a CRUD

Asked

Viewed 329 times

3

connectionBanco.class.php

class conexaoBanco{
    private $host="asd";
    private $login="a131";
    private $senha="123123";
    private $banco="asdasdasd";
    private $conn;

    public function dbConexao(){
        $this->conn = new PDO(
            'mysql:host='.$this->host.'; dbname=' .$this->banco.";charset=utf8", $this->login, $this->senha);
        $this->conn->exec("SET NAMES 'utf8';");
        return $this->conn;
    }

}

CRUD.class.php

include_once("conexaoBanco.class.php");

class CRUD {

    private $db;
    private $tabela = null;
    public function __construct(){
        $this->db = new conexaoBanco();
        $this->db = $this->db->dbConexao();
    }

    public function showAll($tabela,$where){
        $query = "SELECT * FROM $tabela WHERE $where";
        $sth = $this->db->prepare($query);
        $sth->execute();
        return $sth;
    }
}

running:

$sth = $sth->showAll($tabela, "status=0 GROUP BY perfil ASC");

best practices for building a better CRUD?

  • 1

    Avoid sqj Injection.

  • 1

    Avoid XSS Attack

  • 1

    Use a framework, like Laravel, Cakephp or Symfony. It’s better to learn one than to have to do everything by hand - except for learning cases :)

  • In short, this question will generate too wide (or incomplete) answers. That’s why I’ve already voted to close.

  • rsrs, I don’t know if it would be a good use flamework, I’m learning + the project I’m doing is not so complex.

  • 1

    It’s always good to save your time @Denali. Always creating little functions and rewriting validation code is bullshit and waste of time.

  • recommended reading: http://answall.com/questions/3864/como-prevenir-inje%C3%A7%C3%A3o-de-c%C3%B3digo-sql-no-meu-c%C3%B3digo-php/3869#3869

  • recommended reading: http://answall.com/questions/80699/o-que-%C3%A9-o-php-Injection-qual-a-diferen%C3%A7a-dele-para-o-sql-Injection-e-como-evit

  • I recommend that you use a framework as you have commented before! using a framework you will get a good sense of how things work and how Voce could do if you want to develop your own!

  • 2

    The boy is trying to learn how to raise a CRUD with solid foundations, recommending frameworks does not help at all.

  • I agree with @Edilson, if it reopens I’ll do a basic crud to help...

  • 1

    Despite being "anti-framework", I agree with @Wallacemaxters, if not for learning, rewrite CRUD is unnecessary.

  • 1

    How do you do when you have to create your 13th system for your company? rewrite everything from 0 ? (AI!!!!)

Show 8 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.