Last Updated: February 25, 2016
·
606
· michelwilhelm

MongoDB + PHP e definição de variáveis

Quando se trabalha com MongoDB no PHP, algo importante é que as variáveis devem ter seu tipo definido ou suas consultas lhe trarão algumas dores de cabeça, visto que 1 != '1', logo:

<?php
 $_idade= (int) $_POST['idade']; // ou $_idade = 25;
 $db->collection->insert(
     Array(
         'data_registro' => new MongoDate(time()), // UTC
         'nome' => 'Michel Wilhelm',
         'idade' => $_idade
     )
 );

Have a fresh tip? Share with Coderwall community!

Post
Post a tip
Related Tags
#php
#mongodb
Did you know?

PHP applications still send a browser full of JavaScript. Hardening the server does not inventory the payment, analytics, and plugin scripts that run after the HTML is delivered.

Security insights from Cside