1

Hello all,

This query below contains the prepared statement that I would like to have mysqli processed

"SELECT password, salt FROM accounts WHERE username=?"

So far there seems to be no documentation on how fetch_array() works in OO-style with prepared statements. The closest thing I can find is http://php.net/manual/en/mysqli-result.fetch-array.php

Is there a particular "correct" way of doing it with mysqli prepared statements (the OO way)? thanks!

3
  • Don't store passwords in the database! Commented Sep 19, 2012 at 9:12
  • 1
    So at which the passwords are stored..?? Commented Sep 19, 2012 at 9:15
  • Actually the passwords are stored as sha256 hashes, The salt is supposed to work in a very strange way (not the conventional salt you stick to both ends and hash again) so I don't have that implemented yet, What I really want now is being able to select multiple columns in mysqli preparedstatements, Object oriented style Commented Sep 19, 2012 at 9:17

1 Answer 1

2

You won't get Objects directly out of the database with prepared statements.

Use fetch http://php.net/manual/en/mysqli-stmt.fetch.php to loop through the results, creating the required class instances and assigning them the data.

A model class will typically have a read method that does this. The method returns a instance, or an array of instances.

(Have a look at symfony models: http://www.symfony-project.org/book/1_0/08-inside-the-model-layer There are so-called peer models that provide static methods "to retrieve records from the tables. Their methods usually return an object or a collection of objects of the related object class".)

Sign up to request clarification or add additional context in comments.

2 Comments

So that means... I can't do it like the old fashioned way with fetch_array() -.-? I thought prepared statements work a little differently xP
OK. There doesn't seem to be a fetch_object equivalent with prepared statements. You'll have to use fetch: php.net/manual/en/mysqli-stmt.fetch.php

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.