0
I am having trouble inserting a date in the bank with PDO. I have a mirror class in my table in the bank:
class PaginaEntity {
private $id;
private $data;
public function __construct(){
$this->data = date('d-m-y h:i:s A');
//gets and sethers
The class to insert:
class PaginaDao {
public function inserirPagina(PaginaEntity $paginaEntity) {
$conexao = new PDOUtil();
$insert = $conexao->getStance()->prepare("INSERT INTO tabela_teste(data) VALUES(:data)");
$insert->bindValue(":data", $paginaEntity->getData());
$insert->execute();
}
}
And I have the test form:
include_once '../entity/PaginaEntity.php';
include_once '../dao/PaginaDao.php';
include_once '../configs/PDOUtil.php';
if(isset($_GET["acao"])) {
$id = $_POST["id"];
$pagina = new PaginaEntity();
$daoPagina = new PaginaDao();
$daoPagina->inserirPagina($pagina);
}
?>
<form method="post" action="testeInsercaoPagina.php?acao=ok">
<label for="id">id da categoria</label>
<input type="text" name="id"> <br/><br/>
<button type="submit">Gravar</button>
</form>
What happens is the following mistake:
From what I could read,
date_default_timezone_set('UTC')
resolves.– Papa Charlie
even put $this->data = date(’d-m-y h:i:s A', date_default_timezone_set('UTC'); the error no longer exists but does not insert.
– André Martins
There is a definition of time zone in php.ini?
– rray
Put at the beginning of the code, before using the date functions.
– Papa Charlie
Remove 'A' from date creation. Then you can format it with am/pm
– rray
I configured phpini the Timezone and the error ended but now does not insert the value, remembering that in the bank I put even varchar.
– André Martins
Which error appears? It is right to use timestamp for date and time or date for date. You will have sorting and search problems with varchar
– rray
no error appears, so I put varchar temporarily but I will switch to timestamap the variables are receiving the following values id=1, which is a relationship and the date = 19-04-15 12:47:37
– André Martins
in this date format I can leave timestamp even?
– André Martins
@rray switched to timestamp and simply entered, why a date did not insert in a varchar or return error? vc know
– André Martins
Leave the Y-m-d H:i:s format or create the date with mysql now()
– rray
I thought I’d leave it like this you think you’d have trouble’d-m-y h:i:s' in future ordinations?
– André Martins