I'm building a simple login script and have the following:
$sparklyUsername = strtolower($_POST['sparklyUsername']);
$sparklyPassword = $_POST['sparklyPassword'];
if($stmt = $sparklyDatabaseConnection -> prepare("SELECT username FROM SYS_users WHERE username=?")) {
$stmt -> bind_param("s", $sparklyUsername);
$stmt -> execute(); /* Execute the query */
$stmt -> bind_result($result);
$stmt -> fetch();
Now that is all working fine but what if I try and retrieve more than one column, for example:
if($stmt = $sparklyDatabaseConnection -> prepare("SELECT username, password, email FROM SYS_users WHERE username=?")) {
I get an error "Number of bind variables doesn't match number of fields in prepared statement".
Now I am used to VBScript where a query like this returns a recordset (e.g. resultsRS("")) which you then query with a column name (e.g. resultsRS("username")) to get a specific column but from what I can gather, with the code above I bind each column return to a single variable like this:
$stmt -> bind_result($username, $password, $email);
If that's the case, how do I check if now row has been returned at all? In VBScript I would check if the recordset is empty (e.g. IF resultsRS.EOF).
And if I need to loop through all the records returned, all the examples I've seen show something like this:
while ($row = $result->fetch_assoc()) {
But if that seems to create a row from what I would expect to be a column!