Jump to content

Search the Community

Showing results for tags 'mysqli prepare error syntax'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Welcome to PHP Freaks
    • Announcements
    • Introductions
  • PHP Coding
    • PHP Coding Help
    • Regex Help
    • Third Party Scripts
    • FAQ/Code Snippet Repository
  • SQL / Database
    • MySQL Help
    • PostgreSQL
    • Microsoft SQL - MSSQL
    • Other RDBMS and SQL dialects
  • Client Side
    • HTML Help
    • CSS Help
    • Javascript Help
    • Other
  • Applications and Frameworks
    • Applications
    • Frameworks
    • Other Libraries
  • Web Server Administration
    • PHP Installation and Configuration
    • Linux
    • Apache HTTP Server
    • Microsoft IIS
    • Other Web Server Software
  • Other
    • Application Design
    • Other Programming Languages
    • Editor Help (PhpStorm, VS Code, etc)
    • Website Critique
    • Beta Test Your Stuff!
  • Freelance, Contracts, Employment, etc.
    • Services Offered
    • Job Offerings
  • General Discussion
    • PHPFreaks.com Website Feedback
    • Miscellaneous

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Age


Donation Link

Found 1 result

  1. 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.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.