Re: [php-49] mysqli prepared query question

From: David M.
Sent on: Thursday, November 20, 2008 5:50 PM
Greg,

Thank you!  I had forgotten that requirement.

So now I'm left with that feeling like I'm loosing it.  Even with Greg's 'correction,' I am still not able to get what I need.
 - I changed to fetch_assoc which DOES give me the correct key (ex. Name below) from the query/database.  However, I am still not getting the value (e.g. the name of the organization whose ID is 15).

After the execute(), here's what I have:

// Get data
$result = $stmt->store_result();
$row = $result->fetch_assoc();
print_r($row);        // still nothing

Thank you Greg for getting me one step closer... 

any other ideas?
David




--- On Thu, 11/20/08, greg russell <[address removed]> wrote:
From: greg russell <[address removed]>
Subject: Re: [php-49] mysqli prepared query question
To: [address removed]
Date: Thursday, November 20, 2008, 5:12 PM

From what I am reading on here : //1st comment at bottom.

As a consequence, if you want to use to use fetch_row() with an executed prepared statement, first you'll have to get the result out of this statement with mysqli_store_result() or mysqli_use_result().

hope that helps. link to store_result() 

On Thu, Nov 20, 2008 at 4:35 PM, David Malouf <[address removed]> wrote:
I'm wrestling my way into the world of mysqli, especially prepared queries.  This is also my first foray into an Object Oriented approach/style.

Here's my current roadblock that I seem to be stuck on: I am trying to create a simple, 'prepared statements'-type query (SELECT Name FROM organizations WHERE ID = ?).  The only way I can get this to work is to not only use 'bind_param' (to bind a variable to the 'WHERE ID = ?' part of the query) but also use the 'bind_result' method.  If I don't do this, I get no results.

I've been messing around with this so much that I no longer have a true sample to offer.  But here's something close to what I've been doing (you'll notice a lot of book-type names of variables):

// Connect
$mysqli = new mysqli("localhost", "me", "supersecret", "thedatabase");

// Prepare query
$stmt = $mysqli->prepare("SELECT Name FROM organizations WHERE ID=?");

$stmt->bind_param("i", $TheID);

$TheID = 15;

// Execute
$stmt->execute();

// Show results (or not!) -- why doesn't this work?
$row = $stmt->fetch_row();
print_r($row);

// If I use bind_result, it works
$stmt->bind_result($NewResult);
$stmt->fetch();

print_r($NewRsult);     // Yeah!

Why might this be?
David





--
Please Note: If you hit "REPLY", your message will be sent to everyone on this mailing list ([address removed])
This message was sent by David Malouf ([address removed]) from The Seattle PHP Meetup Group.
To learn more about David Malouf, visit his/her member profile
To unsubscribe or to update your mailing list settings, click here

Meetup Support: [address removed]
632 Broadway, New York, NY 10012 USA





--
Please Note: If you hit "REPLY", your message will be sent to everyone on this mailing list ([address removed])
This message was sent by greg russell ([address removed]) from The Seattle PHP Meetup Group.
To learn more about greg russell, visit his/her member profile
To unsubscribe or to update your mailing list settings, click here

Meetup Support: [address removed]
632 Broadway, New York, NY 10012 USA

Our Sponsors

People in this
Meetup are also in:

Sign up

Meetup members, Log in

By clicking "Sign up" or "Sign up using Facebook", you confirm that you accept our Terms of Service & Privacy Policy