Fórum CRUD Genérico #472246
07/03/2014
0
Frederico Brigatte***
Curtir tópico
+ 0Posts
07/03/2014
Rafael Carrenho
Tem este exemplo, espero que seja útil:
http://zaldivar.orgfree.com/php/crud-example-for-php-beginner/
Gostei + 0
07/03/2014
Frederico Brigatte***
Gostei + 0
07/03/2014
Rafael Carrenho
Ah sim! Tem esta classe PHP que simplifica bem mais o processo de desenvolvimento encapsulando todas as queries que seriam escritas "na mão":
https://github.com/adriengibrat/Simple-Database-PHP-Class
Gostei + 0
07/03/2014
Frederico Brigatte***
Gostei + 0
07/03/2014
Marcio Araujo
Tem este exemplo, espero que seja útil:
http://zaldivar.orgfree.com/php/crud-example-for-php-beginner/
legal esse crud. show.
Gostei + 0
07/03/2014
Fred
Gostei + 0
07/03/2014
Claudio Lopes
<?php
header('Content-Type: text/html; charset=ISO-8859-1'); // cabeçalho para acerto de acentuação no windows
/**
* conexão com o banco de dados
*
* @author claudio
*/
class conexao {
protected $bd;
protected $_tabela;
public function __construct(){
try {
//$this->bd = new PDO('mysql:host=SEUSERVIDOR;port=3306;dbname=BASEDADOS', 'USUARIO', 'SENHA' ); //mysql
$this->bd = new PDO("odbc:Driver={SQL Server};Server=SEUSERVIDOR;Database=BASEDADOS; Uid=USUARIO;Pwd=SENHA;charset=UTF-8"); //sqlserver
} catch (PDOException $e) {
print "Error!: " . $e->getMessage() . "<br/>";
die();
}
}
function close(){
if( $this->bd != null ){
$this->db = null;
}
}
public function setTabela($tabela){
$this->_tabela = $tabela;
}
public function getTabela(){
return $this->_tabela;
}
public function insert(array $dados){
$campos = implode(", ", array_keys($dados));
$valores = "'".implode("','", array_values($dados))."'";
("INSERT INTO {$this->_tabela} ({$campos}) values ({$valores})");
"INSERT INTO {$this->_tabela} ({$campos}) values ({$valores})";
if($this->bd->query("INSERT INTO {$this->_tabela} ({$campos}) values ({$valores})")){
$return = 1;
}else{
$return = 0;
}
$this->close();
return $return;
}
public function queryFunction($parametros,$orderby = null,$where = null){
$where = ($where != null ? " WHERE {$where}" : "");
$query = "SELECT * FROM {$this->_tabela} ({$parametros}) {$where} {$orderby}";
$q = $this->bd->query($query);
$q->setFetchMode(PDO::FETCH_ASSOC);
return $q->fetchAll();
}
public function read( $where = null, $orderby = null){
$where = ($where != null ? " WHERE {$where}" : "");
$orderby = ($orderby != null ? " ORDER BY {$orderby}" : "");
"SELECT * FROM {$this->_tabela} {$where} {$orderby} ";
$q = $this->bd->query("SELECT * FROM {$this->_tabela} (nolock) {$where} {$orderby} ");
$q->setFetchMode(PDO::FETCH_ASSOC);
return $q->fetchAll();
$this->close();
}
public function query($query){
$query;
$q = $this->bd->query($query);
$q->setFetchMode(PDO::FETCH_ASSOC);
return $q->fetchAll();
}
public function read_query($query){
$q = $this->bd->query($query);
$q->setFetchMode(PDO::FETCH_ASSOC);
return $q->fetchAll();
$this->close();
}
public function update(array $dados, $where){
foreach ($dados as $ind => $val){
$campos[] = " {$ind} = '{$val}' ";
}
$campos = implode(',', $campos);
"UPDATE {$this->_tabela} SET {$campos} where {$where}";
if($this->bd->query(" UPDATE {$this->_tabela} SET {$campos} where {$where} ")){
$return = 1;
}else{
$return = 0;
}
$this->close();
return $return;
}
public function delete($where){
if($this->bd->query(" DELETE FROM {$this->_tabela} WHERE {$where} ")){
$return = 1;
}else{
$return = 0;
}
$this->close();
return $return;
}
function inverterData2($data2,$sep){
$datainv = "";
if ($data2 == "") {
}else{
$dia=substr("$data2",0, 2);
$mes=substr("$data2",3, 2);
$ano=substr("$data2",6, 4);
$datainv="$ano$sep$mes$sep$dia";
}
return $datainv;
}
}
?>
Gostei + 0
07/03/2014
Frederico Brigatte***
Gostei + 0
07/03/2014
Rafael Carrenho
Sim, mas eu não tenho como explicar tudo na íntegra, mas aqui vai um resumo rápido das funcionalidades.
Primeiro para realizar o download é só clicar no link "Download ZIP" no menu lateral direito e salve em algum diretório de sua preferência, mas vale ressaltar que do diretório que vier no download, só nos interessa um único arquivo, o Db.php, o restante você pode deletar. E crie um arquivo PHP vazio no mesmo diretório apenas para realizarmos estes testes.
E antes de começarmos crie uma base de dados com o nome que preferir e crie uma tabela na base de dados com este script:
CREATE TABLE `agenda` ( `id_contato` int(11) NOT NULL AUTO_INCREMENT, `nome` varchar(45) NOT NULL, `telefone` varchar(9) NOT NULL, PRIMARY KEY (`id_contato`) ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=latin1$$
Uma tabela agenda bem simples apenas para exemplificar. E agora, aquele arquivo PHP vazio que você criou deve ter o seguinte conteúdo:
<?php
include "Db.php"; // Inclusão da classe de CRUD
// Setup do banco de dados: Driver, host, banco de dados, usuário e senha (caso tenha uma senha)
$db = new Db("mysql", "localhost", "DevMedia", "root", "123");
// Um select à "moda antiga"
$meus_contatos = $db->raw( 'SELECT * FROM agenda' );
// Vamos listar os resultados de forma que retorne um array associativo,
// para isto temos o argumento false no método fetch
while($row = $meus_contatos->fetch( false )){
echo "Nome: ".$row['nome']."<br />";
echo "Telefone: ".$row['telefone']."<br /><br />";
}
// E agora um select de forma mais simples
// Isto equivale a um SELECT * FROM agenda
$meus_contatos2 = $db->select('agenda');
while($row = $meus_contatos2->fetch( false )){
echo "Nome: ".$row['nome']."<br />";
echo "Telefone: ".$row['telefone']."<br /><br />";
}
// Vamos trazer apenas a coluna nome
$meus_contatos_apenas_nomes = $db->select('agenda', 'nome');
while($row = $meus_contatos_apenas_nomes->fetch( false )){
echo "Nome: ".$row['nome']."<br />";
}
// Vamos trazer apenas a coluna nome
$contato_fulano = $db->select('agenda', '*',
array(
'nome' => 'Fulano da Silva',
'telefone' => '912345678'
)
);
while($row = $contato_fulano->fetch( false )){
echo "Nome: ".$row['nome']."<br />";
echo "Telefone: ".$row['telefone']."<br /><br />";
}
// Agora vamos criar um registro
$dados = array(
'nome' => 'Dercy Gonçalves',
'telefone' => '987654321'
);
// Para isto passamos no método o nome da tabela e um vetor com
// o nome de cada campo e seu respectivo valor
$db->create( 'agenda', $dados );
// E vamos atualizar este mesmo registro
$dados = array(
'nome' => 'Pedro de Lara'
);
// Para isto inserimos o nome da tabela, um array com nome e valor
// e por último o ID do registro a ser atualizado
$db->update( 'agenda', $dados, 2 );
// Por fim vamos deletar o registro
// Primeiro pelo ID
$db->delete( 'agenda', 1 );
// E agora pelos campos que tem o valor "Pedro de Lara"
$db->delete( 'agenda', 'Pedro de Lara', 'nome' );
?>
Gostei + 0
07/03/2014
Frederico Brigatte***
Gostei + 0
07/03/2014
Frederico Brigatte***
<?php
header('Content-Type: text/html; charset=ISO-8859-1'); // cabeçalho para acerto de acentuação no windows
/**
* conexão com o banco de dados
*
* @author claudio
*/
class conexao {
protected $bd;
protected $_tabela;
public function __construct(){
try {
//$this->bd = new PDO('mysql:host=SEUSERVIDOR;port=3306;dbname=BASEDADOS', 'USUARIO', 'SENHA' ); //mysql
$this->bd = new PDO("odbc:Driver={SQL Server};Server=SEUSERVIDOR;Database=BASEDADOS; Uid=USUARIO;Pwd=SENHA;charset=UTF-8"); //sqlserver
} catch (PDOException $e) {
print "Error!: " . $e->getMessage() . "<br/>";
die();
}
}
function close(){
if( $this->bd != null ){
$this->db = null;
}
}
public function setTabela($tabela){
$this->_tabela = $tabela;
}
public function getTabela(){
return $this->_tabela;
}
public function insert(array $dados){
$campos = implode(", ", array_keys($dados));
$valores = "'".implode("','", array_values($dados))."'";
("INSERT INTO {$this->_tabela} ({$campos}) values ({$valores})");
"INSERT INTO {$this->_tabela} ({$campos}) values ({$valores})";
if($this->bd->query("INSERT INTO {$this->_tabela} ({$campos}) values ({$valores})")){
$return = 1;
}else{
$return = 0;
}
$this->close();
return $return;
}
public function queryFunction($parametros,$orderby = null,$where = null){
$where = ($where != null ? " WHERE {$where}" : "");
$query = "SELECT * FROM {$this->_tabela} ({$parametros}) {$where} {$orderby}";
$q = $this->bd->query($query);
$q->setFetchMode(PDO::FETCH_ASSOC);
return $q->fetchAll();
}
public function read( $where = null, $orderby = null){
$where = ($where != null ? " WHERE {$where}" : "");
$orderby = ($orderby != null ? " ORDER BY {$orderby}" : "");
"SELECT * FROM {$this->_tabela} {$where} {$orderby} ";
$q = $this->bd->query("SELECT * FROM {$this->_tabela} (nolock) {$where} {$orderby} ");
$q->setFetchMode(PDO::FETCH_ASSOC);
return $q->fetchAll();
$this->close();
}
public function query($query){
$query;
$q = $this->bd->query($query);
$q->setFetchMode(PDO::FETCH_ASSOC);
return $q->fetchAll();
}
public function read_query($query){
$q = $this->bd->query($query);
$q->setFetchMode(PDO::FETCH_ASSOC);
return $q->fetchAll();
$this->close();
}
public function update(array $dados, $where){
foreach ($dados as $ind => $val){
$campos[] = " {$ind} = '{$val}' ";
}
$campos = implode(',', $campos);
"UPDATE {$this->_tabela} SET {$campos} where {$where}";
if($this->bd->query(" UPDATE {$this->_tabela} SET {$campos} where {$where} ")){
$return = 1;
}else{
$return = 0;
}
$this->close();
return $return;
}
public function delete($where){
if($this->bd->query(" DELETE FROM {$this->_tabela} WHERE {$where} ")){
$return = 1;
}else{
$return = 0;
}
$this->close();
return $return;
}
function inverterData2($data2,$sep){
$datainv = "";
if ($data2 == "") {
}else{
$dia=substr("$data2",0, 2);
$mes=substr("$data2",3, 2);
$ano=substr("$data2",6, 4);
$datainv="$ano$sep$mes$sep$dia";
}
return $datainv;
}
}
?>
Gostei + 0
08/03/2014
Rafael Carrenho
Então, lembrando você deve baixar o arquivo Bd.php do repositório https://github.com/adriengibrat/Simple-Database-PHP-Class e criar a seguinte tabela no banco de dados:
CREATE TABLE `agenda` ( `id_contato` int(11) NOT NULL AUTO_INCREMENT, `nome` varchar(45) NOT NULL, `telefone` varchar(9) NOT NULL, PRIMARY KEY (`id_contato`) ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=latin1
E um script PHP no mesmo diretório do arquivo Bd.php do nome que preferir.
<?php
include "Db.php"; # Inclusão da classe de CRUD
# Setup do banco de dados: Driver, host, banco de dados, usuário e senha (caso tenha uma senha)
$db = new Db("mysql", "localhost", "DevMedia", "root", "123");
# URL sem query strings, você vai entender o por quê...
$url_original = strtok($_SERVER["REQUEST_URI"],'?');
# Caso seja submetido algum contato
if(count($_POST)){
# Se os campos de nome e telefone estiverem preenchidos
if(!empty($_POST['nome_contato']) && !empty($_POST['telefone_contato'])){
$nome = $_POST['nome_contato'];
$telefone = $_POST['telefone_contato'];
$dados = array(
'nome' => $nome,
'telefone' => $telefone
);
# Caso haja um campo com o ID do contato isso
# indica que é uma alteração de registro
if(!empty($_POST['id_contato'])){
$db->update( 'agenda', $dados, $_POST['id_contato'] );
# Para não ficarmos presos para sempre na edição do
# registro vamos redirecionar para a URL sem a query string
# com o ID do registro a ser editado.
header('Location: '.$url_original);
}else{
# Do contrário, vamos criar um novo registro
$db->create( 'agenda', $dados );
}
}
}
$contato['nome'] = "";
$contato['telefone'] = "";
# Caso seja uma edição ou exclusão de registro
if(count($_GET)){
if(!empty($_GET['editar'])){
# Busca o registro a ser editado
$contato = $db->read('agenda', $_GET['editar'])->fetch( false );
}
if(!empty($_GET['excluir'])){
# Exclui o registro e redireciona para a URL sem
# query string com o ID do registro a ser removido
$db->delete('agenda', $_GET['excluir']);
header('Location: '.$url_original);
}
}
# Selecionando os contatos
$contatos = $db->select('agenda');
?>
<html>
<head>
<meta charset="UTF-8">
</head>
<body>
<form action="" method="POST">
<fieldset>
<legend>Inserir contato</legend>
<label for="nome_contato">Nome:</label><input value="<?php echo $contato['nome'] ?>" maxlength="45" type="text" name="nome_contato" id="nome_contato" />
<label for="telefone_contato">Telefone:</label><input value="<?php echo $contato['telefone'] ?>" maxlength="11" type="text" name="telefone_contato" id="telefone_contato" />
<?php
if(isset($contato['id_contato'])){
echo '<input type="hidden" name="id_contato" value="'.$contato['id_contato'].'" />';
echo '<input type="submit" value="Editar" />';
echo '<a href="'.$url_original.'">Cancelar</a>';
}else{
echo '<input type="submit" value="Criar" />';
}
?>
</fieldset>
</form>
<table>
<tr><th>Nome</th><th>Telefone</th><th colspan="2"></th></tr>
<?php
while($linha = $contatos->fetch( false )){
echo "<tr>";
echo "<td>".$linha['nome']."</td>";
echo "<td>".$linha['telefone']."</td>";
echo "<td><a href='?editar=".$linha['id_contato']."'>Editar</a></td>";
echo "<td><a href='?excluir=".$linha['id_contato']."'>Excluir</a></td>";
echo "</tr>";
}
?>
</table>
</body>
</html>
Gostei + 0
08/03/2014
Frederico Brigatte***
banco.class.php
<?
abstract class banco{
// funcionando
public $servidor = "localhost";
public $usuario = "root";
public $senha = "hp48gx";
public $nomebanco = "aula";
public $conexao = NULL;
public $dataset = NULL;
public $linhasafetadas = -1;
//MÉTODOS
public function __construct(){
$this->conecta();
}//fim construct
public function __destruct(){
if($this->conexao != NULL):
mysql_close($this->conexao);
endif;
}//fim destruct
public function conecta(){
$this->conexao = mysql_connect($this->servidor, $this->usuario,$this->senha,TRUE)
or die($this->trataerro(__FILE__,__FUNCTION__,mysql_errno(),mysql_error(),TRUE));
mysql_select_db($this->nomebanco) or die($this->trataerro(__FILE__,__FUNCTION__,mysql_errno(),mysql_error(),TRUE));
mysql_query("SET NAMES 'utf8'");
mysql_query("SET character_set_connection=utf8");
mysql_query("SET character_set_client=utf8");
mysql_query("SET character_set_results=utf8");
// echo "metodo conecta foi chamado";
}//fim conecta
public function inserir($objeto){
//insert into nometabela (campo1, campo2) values (valor1, valor2)
$sql = "INSERT INTO ".$objeto->tabela." (";
for($i=0; $i<count($objeto->campos_valores); $i++):
$sql .= key($objeto->campos_valores);
if($i < (count($objeto->campos_valores)-1)):
$sql .= ", ";
else:
$sql .= ") ";
endif;
next($objeto->campos_valores);
endfor;
reset($objeto->campos_valores);
$sql .= "VALUES (";
for($i=0; $i<count($objeto->campos_valores); $i++):
$sql .= is_numeric($objeto->campos_valores[key($objeto->campos_valores)]) ?
$objeto->campos_valores[key($objeto->campos_valores)] :
"'".$objeto->campos_valores[key($objeto->campos_valores)]."'";
if($i < (count($objeto->campos_valores)-1)):
$sql .= ", ";
else:
$sql .= ") ";
endif;
next($objeto->campos_valores);
endfor;
//echo $sql;
return $this->executaSQL($sql);
}//fim inserir
public function atualizar($objeto){
//update nometabela set campo1=valor1, campo2=valor2 where campochave=valorchave
$sql = "UPDATE ".$objeto->tabela." SET ";
for($i=0; $i<count($objeto->campos_valores); $i++):
$sql .= key($objeto->campos_valores)."=";
$sql .= is_numeric($objeto->campos_valores[key($objeto->campos_valores)]) ?
$objeto->campos_valores[key($objeto->campos_valores)] :
"'".$objeto->campos_valores[key($objeto->campos_valores)]."'";
if($i < (count($objeto->campos_valores)-1)):
$sql .= ", ";
else:
$sql .= " ";
endif;
next($objeto->campos_valores);
endfor;
$sql .= "WHERE ".$objeto->campopk."=";
$sql .= is_numeric($objeto->valorpk) ? $objeto->valorpk : "'".$objeto->valorpk."'";
// echo $sql;
return $this->executaSQL($sql);
}//fim atualizar
public function deletar($objeto){
//delete from nometabela where campochave=valorchave
$sql = "DELETE FROM ".$objeto->tabela;
$sql .= " WHERE ".$objeto->campopk."=";
$sql .= is_numeric($objeto->valorpk) ? $objeto->valorpk : "'".$objeto->valorpk."'";
//echo $sql;
return $this->executaSQL($sql);
}//fim deletar
public function selecionaTudo($objeto){
$sql = "SELECT * FROM ".$objeto->tabela;
if($objeto->extras_select!=NULL):
$sql .= " ".$objeto->extras_select;
endif;
echo $sql.'<br />';
return $this->executaSQL($sql);
}//fim selecionaTudo
public function selecionaCampos($objeto){
$sql = "SELECT ";
for($i=0; $i<count($objeto->campos_valores); $i++):
$sql .= key($objeto->campos_valores);
if($i < (count($objeto->campos_valores)-1)):
$sql .= ", ";
else:
$sql .= " ";
endif;
next($objeto->campos_valores);
endfor;
$sql .= " FROM ".$objeto->tabela;
if($objeto->extras_select!=NULL):
$sql .= " ".$objeto->extras_select;
endif;
echo $sql.'<br />';
return $this->executaSQL($sql);
}//fim selecionaCampos
public function executaSQL($sql=NULL){
if($sql!=NULL):
$query = mysql_query($sql) or $this->trataerro(__FILE__,__FUNCTION__);
$this->linhasafetadas = mysql_affected_rows($this->conexao);
if(substr(trim(strtolower($sql)),0,6)=='select'):
$this->dataset = $query;
return $query;
else:
return $this->linhasafetadas;
endif;
else:
$this->trataerro(__FILE__,__FUNCTION__,NULL,'Comando SQL nao informado na rotina', FALSE);
endif;
}//fim executaSQL
public function retornaDados($tipo=NULL){
switch(strtolower($tipo)):
case "array":
return mysql_fetch_array($this->dataset);
break;
case "assoc":
return mysql_fetch_assoc($this->dataset);
break;
case "object":
return mysql_fetch_object($this->dataset);
break;
default:
return mysql_fetch_object($this->dataset);
break;
endswitch;
}//fim retornaDados
public function trataerro($arquivo=NULL,$rotina=NULL,$numerro=NULL,$msgerro=NULL,$geraexcept=FALSE){
if($arquivo==NULL) $arquivo="nao informado";
if($rotina==NULL) $rotina="nao informada";
if($numerro==NULL) $numerro=mysql_errno($this->conexao);
if($msgerro==NULL) $msgerro=mysql_error($this->conexao);
$resultado = 'Ocorreu um erro com os seguintes detalhes:<br />
<strong>Arquivo:</strong> '.$arquivo.'<br />
<strong>Rotina:</strong> '.$rotina.'<br />
<strong>Codigo:</strong> '.$numerro.'<br />
<strong>Mensagem:</strong> '.$msgerro;
if($geraexcept==FAlSE):
echo($resultado);
else:
die($resultado);
endif;
}//fim trataerro
}//fim classe banco
?>
paineladm_usuarios.class.php
<?php
require_once("base.class.php");
class paineladm_usuarios extends base{
public function __construct($campos=array()){
parent::__construct();
$this->tabela = "paineladm_usuarios";
if(sizeof($campos)<=0):
$this->campos_valores = array(
"nome" => NULL,
"email" => NULL,
"login" => NULL,
"senha" => NULL,
"ativo" => NULL,
"administrador" => NULL,
"datacad" => NULL
);
else:
$this->campos_valores = $campos;
endif;
$this->campopk="id";
}//fim construct
}//fim paineladm_usuarios
?>
base.class.php
<?php
require_once("banco.class.php");
abstract class base extends banco{
public $tabela = "";
public $campos_valores = array();
public $campopk = NULL;
public $valorpk = NULL;
public $extras_select = "";
//métodos
public function addCampo($campo=NULL,$valor=NULL){
if($campo!=NULL):
$this->campos_valores[$campo] = $valor;
endif;
}//fim addCampo
public function delCampo($campo=NULL){
if(array_key_exists($campo,$this->campos_valores)):
unset($this->campos_valores[$campo]);
endif;
}//fim delCampo
public function setValor($campo=NULL, $valor=NULL){
if($campo!=NULL && $valor!=NULL):
$this->campos_valores[$campo] = $valor;
endif;
}//fim setValor
public function getValor($campo=NULL){
if($campo!=NULL && array_key_exists($campo,$this->campos_valores)):
return $this->campos_valores[$campo];
else:
return FALSE;
endif;
}//fim getValor
}//fim classe base
?>
teste.class.php
<?php
require_once("banco.class.php");
class teste extends banco{
}// fim classe teste
?>
Classe de teste
teste.php
<?php
require_once("classes/paineladm_usuarios.class.php");
$paineladm_usuario = new paineladm_usuarios();
// Informa os registros que vão ser INSERIDOS na tabela do banco de dados
// $paineladm_usuario->setValor('nome','Teste');
// $paineladm_usuario->setValor('email','teste2@gmail.com');
// $paineladm_usuario->setValor('login','teste');
// $paineladm_usuario->setValor('senha','teste');
// $paineladm_usuario->setValor('ativo','s');
// $paineladm_usuario->setValor('administrador','n');
// Executa método INSERIR na classe banco.class.php
// $paineladm_usuario->inserir($paineladm_usuario);
// Informa qual id vai ser ATUALIZADO e VALORES;
// $paineladm_usuario->valorpk = 2;
// $paineladm_usuario->setValor('nome','Teste5 Bla Bla');
// $paineladm_usuario->setValor('email','teste5@gmail.com');
// $paineladm_usuario->setValor('login','teste5');
// $paineladm_usuario->setValor('senha','teste');
// $paineladm_usuario->setValor('ativo','s');
// $paineladm_usuario->setValor('administrador','n');
// Executa método ATUALIZAR na classe banco.class.php
// $paineladm_usuario->atualizar($paineladm_usuario);
// Informa qual id vai ser EXCLUÍDO e VALORES;
// $paineladm_usuario->valorpk = 3;
// Executa método DELETAR na classe banco.class.php
// $paineladm_usuario->deletar($paineladm_usuario);
// Uso do extras_select
// $paineladm_usuario->extras_select = "order by id DESC";
// Executa método SELECIONATUDO na classe banco.class.php
$paineladm_usuario->selecionaTudo($paineladm_usuario);
while($res = $paineladm_usuario->retornaDados()):
echo $res->id . ' / '. $res->nome .' / '. $res->email .' / '. $res->login .' / '. $res->senha .' / '. $res->ativo .' / '. $res->administrador .' / '. $res->datacad .'<br />';
endwhile;
// Remove o campo id da pesquisa
// $paineladm_usuario->delCampo('id');
// Executa método SELECIONACAMPOS na classe banco.class.php
// $paineladm_usuario->selecionaCampos($paineladm_usuario);
// while($res = $paineladm_usuario->retornaDados()):
// echo $res->id . ' / '. $res->nome .' / '. $res->email .' / '. $res->login .' / '. $res->senha .' / '. $res->ativo .' / '. $res->administrador .' / '. $res->datacad .'<br />';
// endwhile;
// Imprime uma barra
echo '<hr />';
// Imprime o conteúdo do objeto paineladm_usuario
echo '<pre>';
print_r($paineladm_usuario);
echo '</pre>';
// Imprime quantas linhas foram afetadas
// echo $paineladm_usuario->linhasafetadas.' registro(s) incluido(s) com sucesso';
?>
Ao fazer o método SELECIONARCAMPOS e testá-lo no arquivo teste.php, retornou isso no navegador:
Notice: Undefined property: stdClass::$id in C:\xampp\htdocs\teste_crud\teste.php on line 52
Notice: Undefined property: stdClass::$ativo in C:\xampp\htdocs\teste_crud\teste.php on line 52
Notice: Undefined property: stdClass::$datacad in C:\xampp\htdocs\teste_crud\teste.php on line 52
/ Fred / ff@gg.com / admin / 21232f297a57a5a743894a0e4a801fc3 / / s /
Notice: Undefined property: stdClass::$id in C:\xampp\htdocs\teste_crud\teste.php on line 52
Notice: Undefined property: stdClass::$ativo in C:\xampp\htdocs\teste_crud\teste.php on line 52
Notice: Undefined property: stdClass::$datacad in C:\xampp\htdocs\teste_crud\teste.php on line 52
/ Teste5 Bla Bla / teste5@gmail.com / teste5 / teste / / n /
Gostei + 0
08/03/2014
Frederico Brigatte***
Gostei + 0
13/03/2014
Claudio Lopes
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)