Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?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;
- }
- ?>
Add Comment
Please, Sign In to add comment