1
Guys, I’m new to PDO and I’m watching some video lessons and also taking a look at the theoretical part, but when trying to accomplish a insert
in DB, is returning me the following error Fatal error: Call to a member function prepare() on array in C:\FullProg\www\Thomas\prog\assets\inc\creat.php on line 19
.
The code is below:
<?php
// include_once 'conexao.php';
function getConnection(){
$host = "localhost";
$user = "root";
$pass = "";
$db_name = "pdo";
try{
$conecta = new PDO("mysql:host=".$host.";dbname=".$db_name, $user, $pass);
return array("conexao" => $conecta, "mensagem" => "Sucesso");
} catch(PDOException $e){
return array("conexao" => null, "mensagem" => "Algo de errado não está certo. <br> Erro: " . $e -> getMessage());
}
}
$conecta = getConnection();
$tipo = "Tipo";
$tamanho = "1M";
$nome = "Prod";
// $sql = "INSERT INTO produtos (nome, tamanho, tipo) VALUES (:nome, :tamanho, :tipo)";
// $stmt = $conecta->prepare($sql);
$stmt = $conecta->prepare("INSERT INTO produtos (nome, tamanho, tipo) VALUES (:nome, :tamanho, :tipo)");
$stmt->bindParam( ':nome', $nome );
$stmt->bindParam( ':tamanho', $site );
$stmt->bindParam( ':tipo', $tipo );
if ($stmt->execute()) {
echo "Dados Salvos " . $nome;
}else{
echo "Ocoreu um erro " . $nome;
}
?>
I’ve already looked in the doc itself that php.net has on and I can’t solve it.
kkkkkkk can’t believe I didn’t see there was no more $site. vlw bro
– Thomas Franklin