Jump to content

Sqlite problemas no cout


pemoamsi

Recommended Posts

tens a ligação correctamente efectuada ?

Sim, estou do mesmo modo a efectuar um insert:

                   	 $result = $db->query('insert into users
                                       values (NULL,
                                               "'.$user.'",
                                               "'.$password.'",
                                               "'.$nivel.'")');

A questão é que queria verificar se tal user já existia e caso contrário registar... mas consigo sempre... pois o cont dá 0 😞

Link to comment
Share on other sites

não estou a ver que abstração estás a usar, mas não deverias guardar o resultado do query e verificar o número de registos no objecto retornado ?

<?php
$db = new PDO('sqlite:backup.sqlite');
$result = $db->prepare('SELECT * FROM users');
$result->execute();
$count = $result->rowCount();
print $count;
?>

Resultado: 0

<?php
$db = new PDO('sqlite:backup.sqlite');
$result = $db->query('SELECT * FROM users');
$count = $result->rowCount();
print $count;
?>

Resultado

Resultado da query directamente na base de dados: 8

Edited by pemoamsi
Link to comment
Share on other sites

http://www.php.net/manual/en/pdostatement.rowcount.php

If the last SQL statement executed by the associated PDOStatement was a SELECT statement, some databases may return the number of rows returned by that statement. However, this behaviour is not guaranteed for all databases and should not be relied on for portable applications.

IRC : sim, é algo que ainda existe >> #p@p
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.