tags:

views:

45

answers:

1

in object oriented php mysqli

I am trying to request a username, and return if it matches a row, without actually returning any user data.

How would I write this?...so far I have...

$sql = "SELECT NULL FROM database WHERE usernick=?";
$stmt = $link->prepare($sql)
$stmt->bind_param('s', $snr);
$stmt->execute();

After this step I need to see if a row matched the query...but I have no idea how to write it, everyone here pretty much writes in mysql if I dont mention I want object oriented mysqli :S

+1  A: 

I'd do it like this:

$stmt->execute();
/* store result */
$stmt->store_result();

printf("Number of rows: %d.\n", $stmt->num_rows);

/* close statement */
$stmt->close();

Cheers,
Fabian

halfdan
select null does indeed fetch the rows (just with NULL as the name and value of the column), so he just needs to do a comparison with $stmt->num_rows and see if it has any results.
dabito
Ah sweet, thanks dabito.
halfdan
I did indeed try to place $stmt->num_rows before and after store_result to see if that made a big difference....and it definately does :)... I appreciate the answer halfdan. Also, is this the only way to write this?...may I ask what you are refering to dabito? just nixing the printf statement? Or did you know another way to go about it?
Matt