MySQLi Prepared Statements
MySQLi Prepared Statements
am 27.03.2006 19:37:40 von Rob Hamilton
Hi
I am current trying to migrate an existing system using MySQLi to use=20
PDO and I have a quick question with regards to Prepared Statements.=20
Essentially I'd like to replicate the Prepared Statement functionality=20
of PDO using MySQLi so that I can gradually update all the required=20
pages to use similar function calls, and then swap everything over in=20
one go rather than spending ages on a big rewrite.
Using PDO you can pass parameters as an array which are bound to the=20
query. Something like:
$stmt =3D $pdo->prepare("SELECT * FROM Blah WHERE foo =3D ?");
$params =3D array("SomeValue");
$stmt->execute($params)
The PDO function "execute" takes 1 parameter which is an array.
There are similar functions in MySQLi such as bind_param and bind_result=20
of which one of the parameters is of type "mixed &var1 [, mixed &...]".
Is it possible to construct an array of this type and pass it to these=20
functions, and if so how?
I know is's possible to call these functions with something like:
$stmt =3D $db->prepare("SELECT * FROM Blah WHERE foo =3D ?");
$paramTypes =3D "s";
$params =3D array("SomeValue");
$stmt->bind_param($paramTypes, $params[0]);
But it seems you cannot pass the array itself using the '&' operator.
Cheers
Rob Hamilton
--=20
___________________________________________________
Play 100s of games for FREE! http://games.mail.com/
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: MySQLi Prepared Statements
am 28.03.2006 06:13:58 von Georg Richter
Am Mo, den 27.03.2006 schrieb Rob Hamilton um 19:37:
Hello Rob,
> Is it possible to construct an array of this type and pass it to these
> functions, and if so how?
For such cases you should use call_user_func_array.
/Georg
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Using OR in a SELECT statement
am 28.03.2006 08:40:07 von Arno Kuhl
Newbie MySQL question...
I have a situation where if I don't have a custom value then I must use the
default value. There will always be a default value but there may also be a
custom value.
I could do this with:
select value where id and custom condition
if (EOF) {
select value where id and default condition
if (EOF) {
// no value found for this id - error, return false
}
}
// return value
If I change this to:
select value where id and (custom condition or default condition)
.... will I always get the custom value if there is one, or do I have to have
2 selects to be sure that I always get the custom value if there is one? IE
does MySQL consistently read and process the OR statement from left to right
or does it change depending on what's most optimal?
Cheers
Arno
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Using OR in a SELECT statement
am 28.03.2006 16:55:21 von Miles Thompson
At 02:40 AM 3/28/2006, Arno Kuhl wrote:
>Newbie MySQL question...
>
>I have a situation where if I don't have a custom value then I must use the
>default value. There will always be a default value but there may also be a
>custom value.
>
>I could do this with:
>
>select value where id and custom condition
>if (EOF) {
> select value where id and default condition
> if (EOF) {
> // no value found for this id - error, return false
> }
>}
>// return value
>
>
>If I change this to:
>
>select value where id and (custom condition or default condition)
>
>... will I always get the custom value if there is one, or do I have to have
>2 selects to be sure that I always get the custom value if there is one? IE
>does MySQL consistently read and process the OR statement from left to right
>or does it change depending on what's most optimal?
>
>Cheers
>Arno
This is really a MySQL question, but check section 12 of the MySQL manual.
Here's the link for operator precedence
http://dev.mysql.com/doc/refman/4.1/en/operator-precedence.h tml
I'd run some simple tests, just on the OR to see how it behaves. I usually
have to make at least two passes on logical conditions to get them right.
Where is your EOF() coming from? If you are cascading the statements, use
mysql_num_rows() or just test for the value returned from mysql_query().
Hope this has been helpful - Miles
--
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.1.385 / Virus Database: 268.3.2/294 - Release Date: 3/27/2006
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php