Extracting array values and transforming into integers

Asked

Viewed 38 times

1

Please anyone who can help me. The question is this, I need to extract two variables from an array and use them as an integer type to compare values between them. The code is this:

$sql = "SELECT *
FROM 
inf_user
WHERE
login = '" . $login
."' and senha = '" . $senha ."'";

try{
    $conn = new PDO('mysql:host=' . $servername . ';dbname=' . $dbname, $username, $password);
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

    $result = $conn->query($sql) or die('Nao foi possivel executar o comando.');
    $rows = $result->fetch();

    extract($rows);

    //echo "\$limite = $limite; \$consultas = $consultas";

    $limite = intval($limite);
    $consultas = intval($consultas);

    var_dump($limite);

The return of var_dump is int(2), but I need it to be just the number 2 without the int(). How do I do?

  • Does your string have a pattern? this looks like a field declaration (SQL). Remember that the var_dump() adds a formatting in the output. Check the output with echo also.

1 answer

0

I usually access the return value by accessing the indexes of the arrays, for example:

$result = $conn->query($sql) or die('Nao foi possivel executar o comando.');
$rows = $result->fetch(PDO::FETCH_ASSOC);

$id = $rows['id'];
$nome = $rows['nome'];

Browser other questions tagged

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