\Dewdrop\Db\DbdeployCliExec

This class makes it easy to run SQL scripts through the CLI tool of your RDBMS. It will attempt to auto-detect the location of your "psql" or "mysql" binaries and will run the scripts in such a way that errors halt execution.

Summary

Methods
Properties
Constants
__construct()
run()
getOutput()
No public properties found
No constants found
exec()
No protected properties found
N/A
createCmd()
detectExecutable()
which()
$output
$binaryPath
$dbType
$username
$password
$hostname
$dbName
N/A

Properties

$output

$output : string

The output generated during script execution. Useful for trouble-shooting failed scripts.

Type

string

$binaryPath

$binaryPath : string

The full path to your "mysql" or "psql" binary, if it is in an abnormal location (e.g. you've got an alternative Postgres installed version in /Applications or /opt).

Type

string

$dbType

$dbType : string

Which type of RDBMS are we using ("pgsql" or "mysql").

Type

string

$username

$username : string

The username used to connect to the DB.

Type

string

$password

$password : string

The password used to connect to the DB.

Type

string

$hostname

$hostname : string

The hostname used to connect to the DB.

Type

string

$dbName

$dbName : string

The name of the database.

Type

string

Methods

__construct()

__construct(string  $dbType, string  $username, string  $password, string  $hostname, string  $dbName, string  $binaryPath = null) 

Note that $dbType must be "pgsql" or "mysql" so that we can construct a CLI command for your DB.

Parameters

string $dbType
string $username
string $password
string $hostname
string $dbName
string $binaryPath

Throws

\Dewdrop\Db\Dbdeploy\Exception

run()

run(string  $path, boolean  $throwExceptions = true) : boolean

Run the supplied SQL script. If it fails, by default, we'll throw an exception with the command's output. If the command generates a successful exit status (0), then we return true. Any non-zero exit status will return false.

Parameters

string $path
boolean $throwExceptions

Throws

\Dewdrop\Db\Dbdeploy\Exception\ScriptExecutionFailed

Returns

boolean

getOutput()

getOutput() : string

Get the full output from the most recent script execution.

Returns

string

exec()

exec(string  $cmd, array  $output, integer  $exitStatus) : string

A little wrapper around the built-in exec() funciton so it can be mocked during testing.

Parameters

string $cmd
array $output
integer $exitStatus

Returns

string

createCmd()

createCmd(  $path) : string

Generate a full CLI command for the supplied path. Notice the additional ON_ERROR_STOP=1 argument in the psql template to ensure it halts execution if an error is encountered. MySQL does that by default.

Parameters

$path

Returns

string

detectExecutable()

detectExecutable() : string

Find the executable using either the manually supplied $binaryPath class property or using Unix's which to find it in the $PATH.

Returns

string

which()

which(  $name) : string

A little wrapper around Unix's which. If which isn't available in and executable in /usr/bin, we just return the input, hoping that the binary can be found in our $PATH.

Parameters

$name

Returns

string