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?
Avoid sqj Injection.
– rray
Avoid XSS Attack
– Wallace Maxters
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 :)
– Wallace Maxters
In short, this question will generate too wide (or incomplete) answers. That’s why I’ve already voted to close.
– Wallace Maxters
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.
– Denali
It’s always good to save your time @Denali. Always creating little functions and rewriting validation code is bullshit and waste of time.
– Wallace Maxters
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
– Wallace Maxters
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
– Wallace Maxters
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!
– RFL
The boy is trying to learn how to raise a
CRUD
with solid foundations, recommending frameworks does not help at all.– Edilson
I agree with @Edilson, if it reopens I’ll do a basic crud to help...
– Cezar
Despite being "anti-framework", I agree with @Wallacemaxters, if not for learning, rewrite CRUD is unnecessary.
– mauricio caserta
How do you do when you have to create your 13th system for your company? rewrite everything from 0 ? (AI!!!!)
– Wallace Maxters