I'm using the CodeIgniter framework, I started my studies a few days ago. I am facing some problems for creating a CRUD. Some of them is the connection to the bank. I would like to insert the values in the table, but it will not, and when I insert it by the terminal and printar in PHP it looks like this:
model_Conta.php:
classModel_contaextendsCI_Model{public$id;public$nome;public$idade;public$profissao;publicfunctionconexao(){try{$conexao=newPDO("mysql:host=localhost;dbname=ListaContatos;charset=utf8", "joao", "");
return $conexao;
}catch(PDOException $erro){
echo "Conexao falhou: ". $erro->getMessage();
}
}
public function inserir($nome, $idade, $profissao){
$PDO = Model_conta::conexao();
$PDO->query("INSERT INTO contatos(nome, idade, profissao) VALUES ($nome, $idade, $profissao);");
}
public function retorna(){
$PDO = Model_conta::conexao();
$contatos = $PDO->query("select * from contatos");
foreach($contatos as $contato){
print_r('<pre>');
print_r($contato);
}
}
}
Base.php:
public function cadastrar(){
$nome = $this->input->post('nome');
$idade = $this->input->post('idade');
$profissao = $this->input->post('profissao');
$this->load->model('Model_conta');
$this->Model_conta->inserir($nome, $idade, $profissao);
}
public function retorna(){
$this->load->model('Model_conta');
$this->Model_conta->retorna();
}
Errors:
Return of table with more values; You are not entering the values in the bank