0
With a problem, basically the data is not being entered in the database, and is not showing error, I am still beginner, and I can not understand where the error is:
Script:
require_once ('config.php');
$idAnime = 5025;
while($idAnime < 8000)
{
$verificaAnime = $crud->select('idMal','animesmal','WHERE idMal = ?')->run([$idAnime]);
$contaRow = $verificaAnime->rowCount();
if($contaRow == 0)
{
$text = $apiMal->get_busca($idAnime);
if(is_array($text))
{
$title = $text['title'];
$id = $text['idAnime'];
$score = $text['score'];
$desc = $text['description'];
$desc = $translate->runTranslate($desc);
$dados = array($id,$title,$desc);
$certo = $crud->insert('animesMal','idMAl = ?, name = ?, description = ?, score = ?')
->run(array($id,$title,$desc, $score));
if($certo)
{
echo 'sucesso ao Adicionar o anime '.'<span class="msg-sucesso">'.$title.'</span>'.' ao banco de dados.<br>';
}else
{
echo 'Erro ao inserir animes no banco de dados<br>Erro: '.$certo;
}
}else
{
echo '<span class="msg-erro">'.$text.'</span><br>';
}
}else
{
echo '<span class="msg-erro">'."ERRO: O anime já existe no banco de dados</span><br>"; // echo var_dump($verificaAnime);
}
$idAnime++;
}
CRUD:::
<?php
namespace Classes;
class Crud{
private $query, $run;
public function __construct()
{
openDatabase();
}
private function set_statement($s)
{
if(openDatabase()){
$this->query = openDatabase()->prepare($s);
} else{
die(closeDatabase($conn));
}
}
// Execulta
private function do_run()
{
$this->query->execute($this->run);
}
public function run($r = [])
{
$this->run = $r;
$this->do_run();
return $this->query;
}
// Funçao que insert dados no banco de dados
public final function insert($table, $values)
{
$this->set_statement('INSERT INTO '.$table.' SET '.$values.'');
return $this;
}
public final function select($fields, $table, $condition = '')
{
$this->set_statement('SELECT ' .$fields.' FROM '.$table.' '.$condition);
return $this;
}
public final function update($table, $values,$condition)
{
'UPDATE $tabela SET mail = ? WHERE id = ?';
$this->set_statement();
return $this;
}
}
How is your Insert function?
– adventistaam
pear ai grandpa add my crud
– Lukas Takahashi
Your Insert is not correct. The way you wrote the
insert
serves for the functionupdate
– adventistaam
What do you mean? That’s the mistake?
– Lukas Takahashi
Try the
=
and leave only the fields– adventistaam
Instead of sending like this:
insert('animesMal','idMAl = ?, name = ?, description = ?, score = ?')
boss like thisinsert('animesMal','idMAl, name, description, score')
– adventistaam
I tried and still not working, and shows no error
– Lukas Takahashi
Before
if($certo)
put thatprint_r($certo->errorInfo()); exit;
– adventistaam
it had returned an error for having removed the = ? , after I put them back it only returns Array ( [0] => 00000 [1] => [2] => )
– Lukas Takahashi
At position 1 of the array shows which message?
– adventistaam
For a better display you put like this:
echo "<pre>"; print_r($certo->errorInfo()); echo "</pre>"; exit;
– adventistaam
So, hj ran the code the way it is in this post and everything worked perfectly kk. Now I’m very lost. PQ have no idea what happened and how it started again kk
– Lukas Takahashi
Strange, because the syntax of Insert is
INSERT INTO tabela (campo1, campo2, campo3) VALUES ()
and notINSERT INTO tabela SET campo1 = 1, campo2 = 2
– adventistaam
pse kk, Vlw for help
– Lukas Takahashi