atom feed9 messages in com.googlegroups.professional-php[Pro. PHP Dev.] Re: Bind Result query
FromSent OnAttachments
Peter NankivellNov 16, 2008 10:36 pm 
Edgar da Silva (Fly2k)Nov 17, 2008 5:22 am 
Fahd MurtazaNov 17, 2008 5:28 am 
Robert GonzalezNov 17, 2008 8:56 am 
Fahd MurtazaNov 17, 2008 8:59 am 
Robert GonzalezNov 17, 2008 9:01 am 
Fahd MurtazaNov 17, 2008 10:32 am 
Peter NankivellNov 17, 2008 3:12 pm 
Peter NankivellNov 17, 2008 4:40 pm 
Subject:[Pro. PHP Dev.] Re: Bind Result query
From:Peter Nankivell (
Date:Nov 17, 2008 3:12:57 pm

My Apologies, I should have given some more information. MySQL5 database and using mysqli in PHP5 to do what I need.

I am converting a project that used to connect to a Postgres DB which has prepared statements in it. While I'm not overly experienced with Postgres, it seems that PG and MySQL handle prepared statement in a different way. PHP requiring columns to be bound to a $var before being fetched ( result.php)

That is all very well, but my problem exists in that I do not want to have to explicitly set which columns I want to collected all the time. So while it is easy to organise: "SELECT name FROM table_name" and then to bind "name" to $name before fetching results I need more flexibility with setting fetch results.

A lot of my queries are "SELECT * FROM table_name", but I have to bind ALL the field names that I am collected before I can fetch the result, otherwise I get a "Number of bind variables doesn't match number of fields in prepared statement." error. What I would like to do is use that query in a prepared statement and be able to get all the fields without having to specify all the column names in bind_result before fetching.

Any help would be very, very much appreciated. Thanks

On Nov 18, 4:33 am, "Fahd Murtaza" <> wrote:


I think what he wants wants is to have something like this

forexample this is the query

"Select id,name,email from table_name"

above is the query that is being executed in

On Mon, Nov 17, 2008 at 9:02 AM, Robert Gonzalez <> wrote:

This is possible even without a framework. What is the desired outcome exactly?

On Mon, Nov 17, 2008 at 9:00 AM, Fahd Murtaza <> wrote:

usually this is possible in PHP frameworks right?

 On Mon, Nov 17, 2008 at 8:57 AM, Robert Gonzalez <> wrote:

When you say bind results are you talking about mapping column names to variable names or a result set to a variable?

On Mon, Nov 17, 2008 at 5:28 AM, Fahd Murtaza <> wrote:

I am copying this example for your help

<?php mysql_connect("localhost", "mysql_user", "mysql_password") or     die("Could not connect: " . mysql_error()); mysql_select_db("mydb");

$result = mysql_query("SELECT * FROM table_name");

while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {     printf("ID: %s  Name: %s", $row["id"], $row["name"]); }

mysql_free_result($result); ?>

On Mon, Nov 17, 2008 at 5:22 AM, Edgar da Silva (Fly2k) <> wrote:

What database system are you using?

In think the *_fetch_array() is the solution for you.

2008/11/17 Peter Nankivell <>:

$query = "SELECT * FROM table_name";

Once I have prepped the query, and executed it, I need to be able to bind the results without explicitly setting the variables for all the columns in the table. Is there anyway to actually do this?

-- Abraços Edgar Ferreira da Silva Engenheiro de Software Campinas - SP (19) 8110-0733

----- Aprenda PHP, cole códigos, saiba das vagas de empregos:

--~--~---------~--~----~------------~-------~--~----~ This group is managed and maintained by the development staff at 360 PSG. An
enterprise application development company utilizing open-source technologies
for todays small-to-medium size businesses.

For information or project assistance please visit :

You received this message because you are subscribed to the Google Groups
"Professional PHP Developers" group. To post to this group, send email to To unsubscribe from this group, send email to For more options, visit this group at -~----------~----~----~----~------~----~------~--~---