C.61 PDOSQLExecTask

The PDOSQLExecTask executes SQL statements using PDO.


The combination of large SQL files and delimitertype set to normal can trigger segmentation faults with large files.

Table C.71: Attributes

urlStringPDO connection URL (DSN)noneYes
useridStringUsername for connection (if it cannot be specified in URL) noneNo
passwordStringThe password to use for the connection (if it cannot be specified in URL)noneNo
srcFileA single source file of SQL statements to execute.noneNo
onerrorStringThe action to perform on error (continue, stop, or abort)abortNo
delimiterStringThe delimiter to separate SQL statements (e.g. "GO" in MSSQL);No
delimitertypeStringThe delimiter type ("normal", "row" or "none"). Normal means that any occurrence of the delimiter terminate the SQL command whereas with row, only a line containing just the delimiter is recognized as the end of the command. None disables all delimiter detection.noneNo
autocommitBooleanWhether to auto (implicitly) commit every single statement, disabling transactions.falseNo
encodingStringEncoding to use for read SQL filesnoneNo

C.61.1 Example

<pdosqlexec url="pgsql:host=localhost dbname=test">
  <fileset dir="sqlfiles">
      <include name="*.sql"/>
<pdosqlexec url="mysql:host=localhost;dbname=test" 
  userid="username" password="password">
  <transaction src="path/to/sqlfile.sql"/>
  <formatter type="plain" outfile="path/to/output.txt"/>


Because of backwards compatibility, the PDOSQLExecTask can also be called using the 'pdo' statement.

<pdo url="pgsql:host=localhost dbname=test">
  <fileset dir="sqlfiles">
      <include name="*.sql"/>

  <!-- xml formatter -->
  <formatter type="xml" output="output.xml"/>

  <!-- custom formatter -->
  <formatter classname="path.to.CustomFormatterClass">
    <param name="someClassAttrib" value="some-value"/>

  <!-- No output file + usefile=false means it goes to phing log -->
  <formatter type="plain" usefile="false" />

C.61.2 Supported Nested Tags

  • transaction

    Wrapper for a single transaction. Transactions allow several files or blocks of statements to be executed using the same PDO connection and commit operation in between.

    Table C.72: Attributes

    srcStringFile with statements to be run as one transactionn/aNo

  • fileset

    Files containing SQL statements.

  • filelist

    Files containing SQL statements.

  • formatter

    The results of any queries that are executed can be printed in different formats. Output will always be sent to a file, unless you set the usefile attribute to false. The path to the output file can be specified by the outfile attribute; there is a default filename that will be returned by the formatter if no output file is specified.

    There are three predefined formatters - one prints the query results in XML format, the other emits plain text. Custom formatters that extend phing.tasks.pdo.PDOResultFormatter can be specified.

    Table C.73: Attributes

    typeStringUse a predefined formatter (either xml or plain). n/aOne of these attributes is required.
    classnameStringName of a custom formatter class (must extend phing.tasks.ext.pdo.PDOResultFormatter).n/a
    usefileBooleanBoolean that determines whether output should be sent to a file.trueNo
    outfileFilePath to file in which to store result.Depends on formatterNo
    showheadersBoolean(only applies to plain formatter) Whether to show column headers.falseNo
    coldelimString(only applies to plain formatter) The column delimiter.,No
    rowdelimString(only applies to plain formatter) The row delimiter.\nNo
    encodingString(only applies to XML formatter) The xml document encoding.(PHP default)No
    formatoutputBoolean(only applies to XML formatter) Whether to format XML output.trueNo