Classes De Inserção
#1
Posted 01/03/2005, 12:29
#2
Posted 01/03/2005, 12:42
<?
class mysql{
var $id;
var $tabela;
var $x;
var $tabela;
var $sql;
function deletar(){
$this -> id = $_GET['id'];
$this -> tabela = "nome_da_tabela;
$this -> x = mysql_query("delete * from ".$this->tabela." WHERE id=".$this->id."");
if($this->x){
print"tabela deletada com sucesso";
}else{
print"tabela não deletada";
}
function select(){
$this ->tabela = "nome_da_tabela";
$this -> sql = mysql_query("select * from ".$this->tabela.");
if($this->sql){
print"tabela selecionada";
}else{
print"tabela não selecionada";
}
}
}
$exe = new mysql();
$exe->deletar();
$exe->select();
?>
#3
Posted 01/03/2005, 12:47
class SqlQuery($type, $where, $limit, $table) { var $query; var $return; function query() { $this->return = mysql_query($this->query); } function Delete($where, $limit,$table) { $this->query = "DELETE FROM $table WHERE $where LIMIT $limit"; } function Select ($where, $limit, $table) { $this->query = "SELECT * FROM $table WHERE $where LIMIT $limit"; } } mysql_connect( ... ); mysql_select_db(...); $sql = new SqlQuery(); $sql->Select("id=1","","tabela"); $retorno = $sql->query();
só acrescentar as funcoes de update, etc
edit
henrique, a sua nao vai funcionar pois nao pode fazer isso:
class mysql{
var $id;
var $tabela;
$this -> id = $_GET['id'];
$this -> tabela = "nome_da_tabela;
, use:
class mysql{
var $id;
var $tabela;
function mysql() {
$this -> id = $_GET['id'];
$this -> tabela = "nome_da_tabela;
}
}
, uma funcao igual ao nome da classe eh chamada quando se instancia a classe. nao se pode definir o valor de uma variavel fora de uma funcao.
Edição feita por: gbr_chacal, 01/03/2005, 12:49.
#4
Posted 01/03/2005, 12:51
<form name="form" method="get" action="<?mysql::deletar();?>">
1 user(s) are reading this topic
0 membro(s), 1 visitante(s) e 0 membros anônimo(s)