Re: what is the point of prepare?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, 2007-10-29 at 10:06 +0000, Hulf wrote:
> Hi,
> 
> Begining using the php5 mysql functions and want to know what is the point of preparing/binding the data before I insert it?
> 
> $prep = $mysqli->prepare ("INSERT INTO cd (cdid,title,artist) VALUES ('0',?,?)");
> $prep->bind_param ('22',$title,$artist);
> 
> Ta,
> 
> R.

With a prepared statement, you can use mysqli_get_metadata() to get
information about the columns of the result that statement will
generate, without having to actually execute the statement (or parse it
yourself).

This comes in really handy if you have dynamically generated SQL and
need to know what the names/types of the columns are going to be before
you execute it.

Mysqli_get_metadata() also includes info on the original names and
tables of the columns (if they have been aliased) and what their types
are.  This is great for generating multi-table insert statements from
dynamically generated SQL queries.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux