The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> bind_param with dynamic # of variables
raphael75
post Apr 6 2012, 05:41 PM
Post #1


Novice
**

Group: Members
Posts: 28
Joined: 12-November 07
Member No.: 4,295



I'm trying to write a variable number of arguments to a table. I was looking in the php documentation of bind_param and it mentioned using a ReflectionClass and invokeArgs to do it. I've been trying and I can't get it to work.

Say this is my array. The first argument is the types string:

$myarr =>
(
[0] = String(20) "sssssi"
[1] = String(6) "'test'"
[2] = String(5) "'ttt'"
[3] = String(8) "'tester'"
[4] = String(12) "'2015-01-01'"
[5] = String(6) "'test'"
[6] = Integer(1) 0
)

And here is the code:
CODE

$res    = $mysqli->prepare($qry);
$ref    = new ReflectionClass('mysqli_stmt');
$method = $ref->getMethod("bind_param");
$method->invokeArgs($res,$myarr);
$res->execute();


Please help me understand what I'm doing wrong. Thanks!

This post has been edited by raphael75: Apr 6 2012, 05:49 PM
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Ephraim F. Moya
post Apr 6 2012, 08:00 PM
Post #2


Advanced Member
****

Group: Members
Posts: 167
Joined: 2-September 07
From: New Mexico
Member No.: 3,702



QUOTE(raphael75 @ Apr 6 2012, 03:41 PM) *

I'm trying to write a variable number of arguments to a table. I was looking in the php documentation of bind_param and it mentioned using a ReflectionClass and invokeArgs to do it. I've been trying and I can't get it to work.

Say this is my array. The first argument is the types string:

$myarr =>
(
[0] = String(20) "sssssi"
[1] = String(6) "'test'"
[2] = String(5) "'ttt'"
[3] = String(8) "'tester'"
[4] = String(12) "'2015-01-01'"
[5] = String(6) "'test'"
[6] = Integer(1) 0
)

And here is the code:
CODE

$res    = $mysqli->prepare($qry);
$ref    = new ReflectionClass('mysqli_stmt');
$method = $ref->getMethod("bind_param");
$method->invokeArgs($res,$myarr);
$res->execute();


Please help me understand what I'm doing wrong. Thanks!


Do you have access to mysqli ?
edit:
Here's my routines for just this stuff:
--------------------------------------------------------------------------------------------
private function writenewuser( $lvl = MEMBER )
{
global $ca; $utn = USERS_TABLE_NAME;

$usr = "{$_POST['rfnam']} {$_POST['rmnam']}. {$_POST['rlnam']}";
$nck = "{$_POST['rnick']}";
$sap = "{$_POST['rssap']}";
$pas = sha1( $_POST['rssap'] );
$fnm = "{$_POST['rfnam']}";
$mnm = "{$_POST['rmnam']}";
$lnm = "{$_POST['rlnam']}";
$str = "{$_POST['rstrt']}";
$ctz = "{$_POST['rctsz']}";
$mal = "{$_POST['rmail']}";

$pm = array( 'issssssssss', $lvl, $usr, $nck, $sap, $pas, $fnm, $mnm, $lnm, $str, $ctz, $mal );

$pq = "INSERT INTO `{$utn}` SET `levl` = ?, `user` = ?, `nick` = ?, `ssap` = ?, `pass` = ?,
`fnam` = ?, `mnam` = ?, `lnam` = ?, `strt` = ?, `ctsz` = ?, `mail` = ? ";

$dbs = new database();
$dbs->ExecSQLi( $pq, $pm );
$dbs->close();
}
---------------------------------------------------------------------------------
public function ExecSQLi( $pq, $pm ) // query, parameters
{
$iqr = $this->db->prepare( $pq );

$bs = call_user_func_array( array( $iqr, 'bind_param' ), $this->refValues( $pm ));

$iqr->execute();
$iqr->close();

return $pq;
}
---------------------------------------------------------------------------------

These are just snippets, they need to be fleshed out.

This post has been edited by Ephraim F. Moya: Apr 6 2012, 09:00 PM
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 19th April 2024 - 05:07 PM