PHP Class PDO works all CRUD on the local server when the select works

Asked

Viewed 394 times

4

I have a problem that I could not solve. I have already researched here and found nothing like it.

I have a PHP application, using the PDO class for database connection. So I got her the CRUD: SELECT, INSERT, UPDATE And DELETE.

Everything works perfectly on my machine. However when I go up to the server I cannot do UPDATE nor insert.

I’m already eliminating the possibilities: The database has all the privileges. PHP version is the same as my server.

The error he returns to me is this Exception:

ERRO AO TENTAR ATUALIZAR ENDEREÇO 
NA LINHA 106, ARQUIVO /home/jdrecargadecartu/public_html/emprestimo/admin/app.dao/EnderecoDao.class.php#0/home/jdrecargadecartu/public_html/emprestimo/admin/app.controllers/UpdateFuncionarioController.php(82): EnderecoDao->editaEndereco(Object(EnderecoModal)) #1 {main} 

If anyone can help me I’d really appreciate it.


Follow one of the class I call all are so:

<?php
/**
 * Created by PhpStorm.
 * User: Fabio Dias
 * Date: 27/09/14
 * Time: 23:15
 */
include_once "../app.connectionfactory/ConnectionFactory.class.php";
include_once "../app.interface/IEndereco.class.php";

class EnderecoDao implements IEndereco
{
    private $conn;

    public function __construct()
    {
        $this->conn = ConnectionFactory::getConnection();
    }

    public function cadastraEndereco(EnderecoModal $endereco)
    {
        $id = 0;
        $result = false;
        $rua = $endereco->getRua();
        $numero = $endereco->getNumResidencia();
        $bairro = $endereco->getBairro();
        $complemento = $endereco->getComplemento();
        $cidade = $endereco->getCidade();
        $uf = $endereco->getUf();
        $cep = $endereco->getCep();


        $sqlCadastraEndereco = "INSERT INTO ENDERECO(RUA, NUMERO, COMPLEMENTO, BAIRRO, CIDADE, UF, CEP)  VALUES(?,?,?,?,?,?,?)";
        $openConn = $this->conn->prepare($sqlCadastraEndereco);
        $openConn->bindParam(1, $rua);
        $openConn->bindParam(2, $numero);
        $openConn->bindParam(3, $complemento);
        $openConn->bindParam(4, $bairro);
        $openConn->bindParam(5, $cidade);
        $openConn->bindParam(6, $uf);
        $openConn->bindParam(7, $cep);

        if($openConn->execute()){

            $count = $openConn->rowCount();


            if($count > 0){
                $id = $this->conn->lastInsertId();
                $endereco->setIdEndereco($id);
                $result = true;
            }
        }else{
            throw new PDOException("ERRO AO CADASTRAR COM O BANCO DE DADOS <br />");
        }



        return $result;
    }

    public function excluiEndereco(EnderecoModal $endereco)
    {
        // TODO: Implement excluiEndereco() method.
    }

    public function listaEndereco()
    {
        // TODO: Implement listaEndereco() method.
    }

    public function editaEndereco(EnderecoModal $endereco)
    {
        $id = $endereco->getIdEndereco();
        $result = false;
        $rua = $endereco->getRua();
        $numero = $endereco->getNumResidencia();
        $bairro = $endereco->getBairro();
        $complemento = $endereco->getComplemento();
        $cidade = $endereco->getCidade();
        $uf = $endereco->getUf();
        $cep = $endereco->getCep();


        $sqlCadastraEndereco = "UPDATE  ENDERECO SET RUA = :rua, NUMERO = :numero, COMPLEMENTO = :complemento, BAIRRO = :bairro, CIDADE = :cidade, UF = :uf, CEP = :cep WHERE ID_ENDERECO = :id";
        $openConn = $this->conn->prepare($sqlCadastraEndereco);
        $openConn->bindParam(':rua', $rua);
        $openConn->bindParam(':numero', $numero);
        $openConn->bindParam(':complemento', $complemento);
        $openConn->bindParam(':bairro', $bairro);
        $openConn->bindParam(':cidade', $cidade);
        $openConn->bindParam(':uf', $uf);
        $openConn->bindParam(':cep', $cep);
        $openConn->bindParam(':id', $id);

        if($openConn->execute()){






                $result = true;

        }else{
            throw new PDOException("ERRO AO TENTAR ATUALIZAR ENDEREÇO <br />");
        }



        return $result;
    }

    public function listaEnderecoId(EnderecoModal $endereco)
    {
        // TODO: Implement listaEnderecoId() method.
    }
}

public function editaEndereco(EnderecoModal $endereco)
{
    $id = $endereco->getIdEndereco();
    $result = false;
    $rua = $endereco->getRua();
    $numero = $endereco->getNumResidencia();
    $bairro = $endereco->getBairro();
    $complemento = $endereco->getComplemento();
    $cidade = $endereco->getCidade();
    $uf = $endereco->getUf();
    $cep = $endereco->getCep();


    $sqlCadastraEndereco = "UPDATE  ENDERECO SET RUA = :rua, NUMERO = :numero, COMPLEMENTO = :complemento, BAIRRO = :bairro, CIDADE = :cidade, UF = :uf, CEP = :cep WHERE ID_ENDERECO = :id";
    $openConn = $this->conn->prepare($sqlCadastraEndereco);
    $openConn->bindParam(':rua', $rua);
    $openConn->bindParam(':numero', $numero);
    $openConn->bindParam(':complemento', $complemento);
    $openConn->bindParam(':bairro', $bairro);
    $openConn->bindParam(':cidade', $cidade);
    $openConn->bindParam(':uf', $uf);
    $openConn->bindParam(':cep', $cep);
    $openConn->bindParam(':id', $id);

    if($openConn->execute()){






            $result = true;

    }else{
        throw new PDOException("ERRO AO TENTAR ATUALIZAR ENDEREÇO <br />");
    }



    return $result;
}
  • Could also put the source code that is giving error.

  • The field id is with auto_increment? rsrsrsrs

  • 1

    In the try-catch make the PDO the error message, with errorinfo

  • Everyone id is auto increment

  • I’m gonna ask you a stupid question... the database access data is correct?

  • Yes They are! because I can log in and he brings the ones who are registered.. So when I go edtar me of error.

  • Verify that the user who is attached to the new mysql account on the web hosting has permission for all operations. Probably the bank access user only has access to reading.

  • For test purposes, change the line: throw new PDOException("ERRO AO TENTAR ATUALIZAR ENDEREÇO <br />"); for print_r($this->conn->errorInfo());

  • You returned this to me but did not update Array ( [0] => 00000 [1] => [2] => ) Array ( [0] => 00000 [1] => [2] => ) Function successfully updated

  • Add these two lines at the beginning of the file, before the includes, ini_set('display_errors', true);&#xA; error_reporting(E_ALL);. Direct through the database you can include/change records?

  • Oops I’m sorry I ended up fooling myself here, you print_r it must be that way: print_r($openConn->errorInfo());

  • 4

    Person I want to thank all of you for trying to help me. But I can solve the problem and I want to share here to help other people. Silly stuff people. I am using windows on my machine. So the server is lixux. So what? And so I was using the table name in high box like this: ADDRESS, RUN, USER. There was the problem. The linux server does not accept. In this way I put normal: address, function, user and it worked gorgeous gorgeous. I hope it helps other people And thank you all.

Show 7 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.