Exception on execute() with prepared statements

Exception on execute() with prepared statements

By : user2955653
Date : November 22 2020, 10:40 AM
this will help Found the answer. According to this link, the solution is to encapsulate your field names. PHP PDO Syntax error or access violation: 1064 on insert
In the previous link, "desc" was a reserved keyword. In your case, "group" is a reserved word. http://dev.mysql.com/doc/refman/5.6/en/reserved-words.html
code :
$sql = "INSERT INTO `users` (`user_name`, `group`) VALUES (?, ?)";

Share : facebook icon twitter icon
PHP, MySQL prepared statements - can you use results of execute more than once by calling data_seek(0)?

PHP, MySQL prepared statements - can you use results of execute more than once by calling data_seek(0)?

By : Ed. Urrutia
Date : March 29 2020, 07:55 AM
Does that help I found where this code was going wrong. It had nothing to do with my use of the prepared statement functions, just the placement of the data_seek. I sought help from SO a little too soon :)
The loop code that now works exactly as I wanted is as follows:
code :
while ($q1 = $outer_query->fetch_object()) {
    while ($stmt->fetch()) {
        if ($q1->field1 == $var1) { // looking for a match
            $obj = new stdClass();
            $obj->var1 = $var1;
            $obj->var2 = $var2;
            $obj_array[] = $obj;
            break;               // found match, so leave inner                
    $stmt->data_seek(0); // reset for outer loop
// this was always here, forgot it in original post
$outer_query->data_seek(0) // reset for next iteration of foreach
Can't execute prepared statements using nested while loops

Can't execute prepared statements using nested while loops

By : emawby
Date : March 29 2020, 07:55 AM
will help you You cannot prepare() a statement while the connection has rows waiting to be fetched from another statement. You must first either close the previous result set or fetch all rows from it.
code :
echo "<h3>$location</h3><div>";
// Substitute a query() call and $day0 can be inserted directly.
// This one query fetches all locations sorted...
$query = $dbconn->query("
   COALESCE( CountDesk, 0 ) total,
   desk d
     SELECT COUNT(booked.desk_id) CountDesk, desk_id FROM booked WHERE booking_id >= $day0
   )b ON d.desk_id = b.desk_id 
 ORDER BY location");

// Store the last location in a variable which starts empty...
$location = "";

while($row = $query->fetch_assoc()) {
  // on change of $location, update the variable.
  if ($location !== $row['location']) {
    $location = $row['location'];
    // And output the new location value
     echo "<h3>$location</h3><div>";

  // Do the rest of your loop.
  $total = count($bookingTimes) * 14 - $row['total'];
  echo '<a href="?page=desk&desk='.$row['desk_id'].'"><div class="desk"><b>'.$row['name'].' 
  ('.$total.' Available Bookings)</b><li>Facilities:';
    echo " Phone,";
    echo " Fax Machine,";
    echo " Laptop Dock.";
    echo " Desktop Workstation.";
  echo '</li></div></a><hr />';
echo '</div>';
while ($row = $first_query->fetch()) {
  // Append all onto an array
  $first_query_rows[] = $row;
// Then loop over that
foreach ($first_query_rows as $row) {
  // Do a new query with $row
How to execute two different php prepared statements inside a foreach loop?

How to execute two different php prepared statements inside a foreach loop?

By : vinoth kanna
Date : March 29 2020, 07:55 AM
help you fix your problem Just like the comments above, I'd suggest another way and use CONCAT of MySQL built-in function instead of fetching all the rows from the first prepare:
code :
$updatecolumn = $link->prepare("UPDATE `table` SET `column` = CONCAT(`column`, ?) WHERE id = ?");
$updatecolumn->bind_param("si", $addedstring, $a_value);
Should I use bindParam(), bindValue(), or execute() for PDO prepared statements

Should I use bindParam(), bindValue(), or execute() for PDO prepared statements

By : Joshua Strickland
Date : March 29 2020, 07:55 AM
With these it helps Security wise, there is not a single problem with sending parameters into execute(). So, your concern is superfluous. Given strings are treated safely AND we are sending all our parameters as strings, we can logically conclude that all parameters are treated safely (note that I don't blame your question. It's always better to ask than sorry. I am just making things straight).
The only possible issue with treating all parameters as strings is on the database server side. Yet most database servers allow loose typing in SQL, means any data literal will be recognized and treated properly, despite being sent as a string. There are only few edge cases when it won't work. Here is an excerpt from my PDO tutorial on the matter:
PDO with Mulitple Update prepared statements failing to execute

PDO with Mulitple Update prepared statements failing to execute

By : user1992416
Date : March 29 2020, 07:55 AM
around this issue I am trying to construct a PDO multiple prepared statement that updates 2 tables.
code :
try {
$conn = new PDO('mysql:host=localhost;dbname=*', '*', '*');
$conn->exec("SET CHARACTER SET utf8");      // Sets encoding UTF-8

$est_id = $_POST['est_id'];
$known_for = $_POST['known_for'];
$street_address = 'addressToAdd';

$sqlKnown = "UPDATE `theList` SET `known_for` = :known_for WHERE `id` = :est_id";
$stKnown = $conn->prepare( $sqlKnown );
  ':est_id' => $est_id,
  ':known_for' => $known_for,

$sqlStreet = "UPDATE `est_address` SET `street_address` = :street_address WHERE `id` = :est_id";
$stStreet = $conn->prepare( $sqlStreet );
  ':est_id' => $est_id,
  ':street_address' => $street_address

  $conn = null;        // Disconnect
catch(PDOException $e) {
  echo $e->getMessage();
Related Posts Related Posts :
  • How to make a sitemap using zend framework 1
  • Laravel: array to Model with relationship tree
  • What is the best way to store multiple checkbox values in the database and work with it later on
  • Why does foreach copy the array when we did not modify it in the loop?
  • Receive Jquery/Ajax Post Request in PHP
  • How to better use the if(!empty()){ //codes} statement
  • PHP error mysql_close() boolean given
  • Move an image file from one server to another using PHP
  • PHP: Encoding non ISO-8859-1 charactrers into utf8
  • Handling MySQL errors in PHP
  • Object orientated mysql num_rows query in one line
  • Remove not closed html elements from end of text
  • Generate random ENUM value [PHP, MySQL]
  • Deleting data from table using jQuery and SQL
  • How to make sure the constructor is executed when I'm trying to reach a static property?
  • Trying to understand arrow next to PHP function
  • Form using external php file to show "Sucess"
  • WooCommerce - new shipping method - how to query individual product weights
  • Common integer representation over variable casting?
  • PHP - Prevent client from tampering the ID of a form
  • unexpected T_PUBLIC error
  • Types of testcases in PHPUnit
  • keeping a LDAP user logged in with PHP session
  • Detect if browser supports WebP format? (server side)
  • real_escape_string not cleaning up entered text
  • E-commerce products filter
  • Why having more than one test method in a file using Laravel raises error?
  • PHP Escaped special characters to html
  • Basic prepared statement not INSERTING
  • PHP combobox not showing in HTML table
  • MySql PHP row request to variable
  • Join two tables with one table has multiple rows matching
  • Looping through users with Instagram API requests is REALLY slow
  • Unable to add 30 days to date within loop
  • Return from mysqli_query() into array
  • php rename() function returns "No such file or directory" error
  • form submit inside navigation menu
  • PHP: reasons to use GET and POST request at the same time?
  • Is break; required after die() php
  • little depth of session in php
  • Authentication Logon page not working using PHP and Oracle on Apache / Windows 2008
  • Magento reindexing error product flat data
  • Laravel 4: Running composer when deploying to Heroku
  • Long Polling or WebSockets
  • How to use mysqli_stmt_bind_param for integers, boolean, etc
  • Determining the content of a link
  • MYSQL and PHP update events?
  • PHP explode all square bracket
  • Transparent hexagon-masked collage using PHP GD
  • Plugins or text do NOT show up on custom wordpress template
  • inserting data into mysqli database
  • Two arguments to closure function laravel
  • UnClear image exported by ffmpeg from mp4 file
  • is the time of computer and localhost same?
  • change custom data- value after ajax post success
  • Can We Restrict PHP Variables to accept only certain type of values
  • csv file is inserting a blank row in the last of other rows into mysql table
  • How to convert special characters in xml using php?
  • Mcrypt are very confusing
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org