Advertisement
CoderXco

AutoBind

Jul 8th, 2014
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.58 KB | None | 0 0
  1. // THIS IS REALLY REALLY ROUGH EXPERIMENTAL CODE
  2.  
  3. // CURRENT ERRORS - Fatal error: Cannot pass parameter 2 by reference in C:\xampp\htdocs\wcx\admin\test.php on line 92
  4. // USUALLY $a='1' etc fixes this problem
  5. // Using $a='3',$b='4',$c='5',$d='7',$e='8' in bind_param works fine but when passed in as $where.. ERROR!
  6.  
  7. // AUTO BIND FUNCTION
  8. function getBindParams($params) {
  9. if ($params != null) {
  10. $types = '';                        
  11.     foreach ($params as $param) {        
  12.         if (is_int($param)) {
  13.             $types .= 'i';              
  14.         }
  15.         elseif (is_float($param)) {
  16.             $types .= 'd';              
  17.         }
  18.         elseif (is_string($param)) {
  19.             $types .= 's';            
  20.         }
  21.         else {
  22.             $types .= 'b';            
  23.         }
  24.     }
  25. }
  26.         $bind_names = array();
  27.         $types = array($types);
  28.        
  29.         for ($i=0; $i<count($params);$i++) {
  30.             //$types = $params[$i];
  31.         }
  32. // RETURN THE TYPES
  33.         foreach($types as $type) {
  34.             return $type;
  35.         }
  36.  
  37. }
  38.  
  39. // TEMP ARRAY
  40. $params = array('3','4','5','7','8');
  41. // TEMP LETTER ARRAY FOR VARS
  42. $letters = array('a', 'b', 'c', 'd', 'e'); 
  43. $types = '';
  44. $wheres = '';
  45. foreach($params as $index => $param) {
  46.     $types .= '?';
  47.     if($index+1 !== count($params)) {
  48.         $types .= ',';
  49.     }
  50. }
  51.  
  52. //$letters = array($letters);
  53. //foreach($letters as $letter) {
  54. //$letter = $letter;
  55. //."'". $where . "'"
  56.  
  57. // ASSIGN VALUES TO A VARIABLE AUTOMATICALLY
  58. foreach($params as $index => $where) {
  59.     $wheres .= '$' . array_pop($letters) .'='."'". $where . "'";
  60.  
  61.     if($index+1 !== count($params)) {
  62.         $wheres .= ',';
  63.     }
  64. }
  65. //}
  66.  
  67. $bind_names = array();
  68. $types = array($types);
  69. $wheres = array($wheres);
  70.  
  71. foreach($types as $type) {
  72.     $type = $type;
  73. }  
  74.  
  75. foreach($wheres as $where) {
  76.     $where = $where;
  77. }  
  78. //print_r($where);
  79.     //$where = implode(',',$where);
  80.     //"','", $myArray) . "'"
  81.     //$where = implode("','", $where . "'");
  82.  
  83. $query = 'SELECT article_id FROM wcx_articles WHERE article_id IN ('. $type .')';
  84. //$stmt = $backend->prepareIt($query);
  85. echo $query.'<br />';
  86. echo $where.'<br />';
  87. $stmt = $backend->prepareIt('SELECT article_id FROM wcx_articles WHERE article_id IN ('. $type .')');
  88. //echo $stmt;
  89. $bindParams = getBindParams($params);
  90. echo $bindParams.'<br />';
  91. //$where = explode(',',$where);
  92. print_r($where);
  93. //echo $where;
  94. //call_user_func_array(array($stmt,'bind_param'),$params);
  95.  
  96. // $where would essentially look like this!
  97. //$a='3',$b='4',$c='5',$d='7',$e='8'
  98.  
  99. // ATTEMPT TO PASS THE VALUES IN TO BIND_PARAM +1 needed to match number of binds
  100. $stmt->bind_param($bindParams, $where+1);
  101. $stmt->execute();
  102. $stmt->bind_result($result);
  103. print_r($stmt);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement