ADOdb

Database Abstraction Layer for PHP

User Tools

Site Tools


v5:reference:connection:autoexecute

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
v5:reference:connection:autoexecute [2015/07/22 16:33]
mnewnham
v5:reference:connection:autoexecute [2021/01/25 03:07] (current)
mnewnham
Line 1: Line 1:
-====== AutoExecute ====== +====== autoExecute ======
-~~NOTOC~~ +
-<WRAP important> +
-Because the ''$magicq'' option emulates to some degree the [[http://php.net/manual/en/security.magicquotes.whynot.php|PHP Magic Quotes]] functionality, and if subject to the same issues regarding portability and SQL injections attacks, it is likely to come under discussion regarding modification or removal in releases > 6.0.0 +
-</WRAP>+
 <WRAP info> <WRAP info>
-[[reference:adodb_quote_fieldnames|$ADODB_QUOTE_FIELDNAMES]] provides control over the quoting and casing of fieldnames, especially useful when fieldnames contain special characters+autoExecute is designed to provide a robust simple interface to record updating and insertion. As such, it contains multiple layers of table, column and data validation to ensure data integrity prior to record insertion or update. Consequently, there may be some performance degradation when used for large numbers of record updates. Consider using [[v5:reference:connection:execute|execute()]] for that purpose instead.
 </WRAP> </WRAP>
 +~~NOTOC~~
 <WRAP right box> <WRAP right box>
 +== See Also ==
 +[[v5:reference:adodb_quote_fieldnames|$ADODB_QUOTE_FIELDNAMES]]
 == Syntax == == Syntax ==
-    bool AutoExecute(+    bool autoExecute(
        string $tables,        string $tables,
        string[] $arrFields,        string[] $arrFields,
        string $mode,        string $mode,
        optional mixed $where=false        optional mixed $where=false
-       optional bool $forceupdate=false +       optional bool $forceUpdate=false
-       optional bool $magicq=false+
        )        )
  
Line 22: Line 20:
  
 ===== Description ===== ===== Description =====
-AutoExecute can automatically generate and execute INSERT and UPDATE statements on a given table with this function, and is a wrapper for [[reference:GetInsertSQL|GetInsertSQL()]] and [[reference:GetUpdateSQL|GetUpdateSQL()]]+The function ''autoExecute()'' can automatically generate and execute INSERT and UPDATE statements on a given table with this function, and is a wrapper for [[v5:reference:connection:getinsertsql|getInsertSQL()]] and [[v5:reference:connection:getupdatesql|getUpdateSQL()]]
  
-AutoExecute() inserts or updates `$tablegiven an array of `$arrFields`, where the keys are the field names and the array values are the field values to store. Note that there is some overhead because the table is first queried to extract key information before the SQL is generated. We generate an INSERT or UPDATE based on `$mode(see below). +autoExecute() inserts or updates **$table** given an array of **$arrFields**, where the keys are the field names and the array values are the field values to store. Note that there is some overhead because the table is first queried to extract key information before the SQL is generated. An INSERT or UPDATE is generated based on **$mode** (see below). 
  
 ==== $table ==== ==== $table ====
Line 33: Line 31:
  
 ==== $mode ===== ==== $mode =====
-Legal values for `$mode` are +Legal values for ` $mode ` are 
  
 ^String^Integer^Constant^ ^String^Integer^Constant^
Line 42: Line 40:
 The $where clause is required if $mode == 'UPDATE' The $where clause is required if $mode == 'UPDATE'
  
-==== $forceupdate ====+==== $forceUpdate ====
  
 ^Value^Description^Overhead^ ^Value^Description^Overhead^
Line 48: Line 46:
 |true|All fields provided are updated|The constructed statement may be considerably larger| |true|All fields provided are updated|The constructed statement may be considerably larger|
    
-==== $magicq ====  
-^Value^Description^ 
-|false|Does not attempt to quote special characters in character fields e.g. \0| 
-|true|Attempts to quote special characters, e.g. \0 becomes \\\0 to allow database insertion| 
- 
 ==== Usage ==== ==== Usage ====
- +<code php> 
-AutoExecute($table, $arrFields, $mode, $where=false, $forceUpdate=true,$magicq=false+autoExecute($table, $arrFields, $mode, $where=false, $forceUpdate=true) 
 +</code>
  
 === Insert example === === Insert example ===
 <code php> <code php>
 $table               = 'people' $table               = 'people'
-$record["firstName"] = "Carol"; +$record["first_name"] = "Carol"; 
-$record["lastName" = "Smith"; +$record["last_name" = "Smith"; 
  
-$conn->AutoExecute($table,$record,'INSERT');+$conn->autoExecute($table,$record,'INSERT');
  
 /* /*
- * result executes "INSERT INTO people (firstName,lastName) values ('Carol',Smith')";+ * result executes "INSERT INTO people (first_name,last_name) values ('Carol',Smith')";
  */  */
 </code> </code>
Line 74: Line 67:
 <code php> <code php>
 $table               = 'people' $table               = 'people'
-$record["firstName"] = 'Carol'; +$record["first_name"] = 'Carol'; 
-$record["lasTname" = 'Jones';  +$record["last_name" = 'Jones';  
-$where               = "lastname like 'Sm%'";+$where               = "last_name like 'Sm%'"; 
 + 
 +$conn->autoExecute($table,$record,'UPDATE', $where); 
 + 
 +/* 
 + * result executes "UPDATE people SET first_name='Carol',last_name='Jones' WHERE last_name like 'Sm%'"; 
 + */ 
 +</code> 
 + 
 +In situations where the table names contain certain special characters, such as dashes, the [[v5:reference:adodb_quote_fieldnames|$ADODB_QUOTE_FIELDNAMES]] setting can be used to wrap the table and field names. 
 + 
 +<code php> 
 +$ADODB_QUOTE_FIELDNAMES = 'NATIVE'; 
 +$table               = 'people' 
 +$record["first-name"] = 'Carol'; 
 +$record["last-name" = 'Jones';  
 +$where               = "last_name like 'Sm%'";
  
-$conn->AutoExecute($table,$record,'UPDATE', $where);+$conn->autoExecute($table,$record,'UPDATE', $where);
  
 /* /*
- * result executes "UPDATE people SET firstName='Carol',lasTname='Jones' WHERE lastname like 'Sm%'";+ * result executes "UPDATE `peopleSET `first-name`='Carol',`last-name`='Jones' WHERE `last-name` like 'Sm%'";
  */  */
 </code> </code>
v5/reference/connection/autoexecute.1437575633.txt.gz · Last modified: 2017/04/21 11:37 (external edit)