Search the Community
Showing results for tags 'mysqli prepare error syntax'.
-
I'm trying to upgrade from mysql to mysqli and I'm having real problems. I've finally got connected to the database, I'm now having problems using the prepare with the bind functionality. $sql = "INSERT INTO tb_test (field1,field2,field3) VALUES {?, ?, ?}"; $types = Array('s','s','i'); $values = Array('field1','field2','1'); if(!$mysqli->execute_bind($sql,$types, $values)) { } echo $mysqli->getErrorMsg(); echo '<br />'; print_r($mysqli->getErrorLst()); echo '<br />'; this is my function public function execute_bind($Query, $Types, $Values, $Commit = true, $AutoCommit = true) { # set autocommit mysqli_autocommit($this->_mysqli, $AutoCommit); $bind = new BindParam; $arrParams = array(); echo 'step 1<br />'; $numValues = count($Values); $type = array(); $val = array(); # process the types if(is_array($Types)) { # array passed foreach($Types as $value){ # must have the same number of types as values $type[] = $value; } } echo 'step 2:<br />'; print_r($type); echo '<br />'; # process the values if(is_array($Values)) { echo 'step 2:<br />'; print_r($Values); echo '<br />'; for($i=0;$i<$numValues;$i++) { if($this->check_type($Values[$i],$type[$i])) { array_push($val, $Values[$i]); $bind->add($type[$i], $val[$i]); } else { $this->errorMsg .= mysqli_stmt_error($stmt); array_push($this->errorLst,mysqli_error_list($stmt)); $this->errorMsg = "Type/Value combination does not match. @" . $i; return false; } } } else { # only one value passed if($this->check_type($Values,$type)) { $bind->add($Types, $Values); } else { $this->errorMsg = "Type/Value combination does not match."; return false; } } echo 'step 3:<br />'; print_r($bind->get()); echo '<br />'; # values need to be passed by reference for PHP 5.3 $arrParams = $this->refValues($bind->get()); echo 'step 4:<br />'; if ($stmt = mysqli_prepare($this->_mysqli, $Query)) { // <<<<<<<<<< the error is happening here echo 'step 5:<br />'; $method = new ReflectionMethod('mysqli_stmt', 'bind_param'); $method->invokeArgs($stmt, $arrParams); # Execute the statement mysqli_stmt_execute($stmt); # check to see if the execute worked $numRows = mysqli_affected_rows($this->_mysqli); echo 'step 6:<br />', $numRows; echo '<br />'; if($numRows == 0) { # something failed in this execute $this->errorMsg = mysqli_stmt_error($stmt); $this->errorLst = mysqli_error_list($stmt); return false; } # close statement echo 'step 7:<br />'; mysqli_stmt_close($stmt); } else { echo 'step 8:<br />'; $this->errorMsg = mysqli_error($this->_mysqli); return false; } echo 'step 9:<br />'; return true; } this is the results: step 1 step 2: Array ( [0] => s [1] => s [2] => i ) step 2: Array ( [0] => field1 [1] => field2 [2] => 1 ) step 3: Array ( [0] => ssi [1] => field1 [2] => field2 [3] => 1 ) step 4: step 8: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '{?, ?, ?}' at line 1 Array ( ) The error I'm getting is the "generic" and really doesn't help me trouble shoot. I know I'm passing matching type/values. I know the table exists with the right field types.