Note that there are some explanatory texts on larger screens.

plurals
  1. POComplicated PDO MYSQL query not working
    text
    copied!<p>I've written a php function that allows you to update any entry in any table with any string values (one or multiple). PDO does not throw any errors, though the script does not seem to work! I've checked the name of the database, tables and fields multiple times. It's all correct. This is the only query in my functions that does not work. I believe it has something to do with the array im passing in to the SQL statement and the PDO->bindParam() function.</p> <p>Code: </p> <pre><code>public function updateTableDetail($table, $id, $params) { include($this-&gt;doc_root . 'config/config.php'); if (is_array($params)) { foreach ($params as $param) { $param = Utilities::escapeString($param); } } else { throw new InvalidInputException(InputErrors::NOTANARRAY); } if (is_nan($id)) throw new InvalidInputException(InputErrors::NOTANUMBER); $table = Utilities::escapeString($table); $sql = "UPDATE " . $table . " SET " . $config['table_field_updated'] . " = :updated"; while (current($params)) { $sql .= "," . key($params) . " = :" . key($params); next($params); } reset($params); $sql .= " WHERE id = :id AND " . $config['userId'] . " = :userId"; if ($this-&gt;serverConnector == null) { $this-&gt;serverConnector = new ServerConnector(); } if ($this-&gt;db == null) { $this-&gt;db = $this-&gt;serverConnector-&gt;openConnectionOnUserDb($this-&gt;dbname); } $stmt = $this-&gt;db-&gt;prepare($sql); $updated = date("Y-m-d H:i:s"); $stmt-&gt;bindParam(':updated',$updated); $stmt-&gt;bindParam(':id',$id); $stmt-&gt;bindParam(':userId',$this-&gt;userId); while ($param = current($params)) { $stmt-&gt;bindParam(":".key($params),$param); next($params); } reset($params); $stmt-&gt;execute(); } </code></pre> <p>EDIT: Don't worry about the include statement, the $config[]-array and the class-variables. It's all working aswell. Tested their values already.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload