code
stringlengths 31
1.39M
| docstring
stringlengths 23
16.8k
| func_name
stringlengths 1
126
| language
stringclasses 1
value | repo
stringlengths 7
63
| path
stringlengths 7
166
| url
stringlengths 50
220
| license
stringclasses 7
values |
---|---|---|---|---|---|---|---|
public function usingConnection($name, callable $callback)
{
$previousName = $this->getDefaultConnection();
$this->setDefaultConnection($name);
return tap($callback(), function () use ($previousName) {
$this->setDefaultConnection($previousName);
});
}
|
Set the default database connection for the callback execution.
@param string $name
@param callable $callback
@return mixed
|
usingConnection
|
php
|
illuminate/database
|
DatabaseManager.php
|
https://github.com/illuminate/database/blob/master/DatabaseManager.php
|
MIT
|
protected function refreshPdoConnections($name)
{
[$database, $type] = $this->parseConnectionName($name);
$fresh = $this->configure(
$this->makeConnection($database), $type
);
return $this->connections[$name]
->setPdo($fresh->getRawPdo())
->setReadPdo($fresh->getRawReadPdo());
}
|
Refresh the PDO connections on a given connection.
@param string $name
@return \Illuminate\Database\Connection
|
refreshPdoConnections
|
php
|
illuminate/database
|
DatabaseManager.php
|
https://github.com/illuminate/database/blob/master/DatabaseManager.php
|
MIT
|
public function getDefaultConnection()
{
return $this->app['config']['database.default'];
}
|
Get the default connection name.
@return string
|
getDefaultConnection
|
php
|
illuminate/database
|
DatabaseManager.php
|
https://github.com/illuminate/database/blob/master/DatabaseManager.php
|
MIT
|
public function setDefaultConnection($name)
{
$this->app['config']['database.default'] = $name;
}
|
Set the default connection name.
@param string $name
@return void
|
setDefaultConnection
|
php
|
illuminate/database
|
DatabaseManager.php
|
https://github.com/illuminate/database/blob/master/DatabaseManager.php
|
MIT
|
public function supportedDrivers()
{
return ['mysql', 'mariadb', 'pgsql', 'sqlite', 'sqlsrv'];
}
|
Get all of the supported drivers.
@return string[]
|
supportedDrivers
|
php
|
illuminate/database
|
DatabaseManager.php
|
https://github.com/illuminate/database/blob/master/DatabaseManager.php
|
MIT
|
public function availableDrivers()
{
return array_intersect(
$this->supportedDrivers(),
str_replace('dblib', 'sqlsrv', PDO::getAvailableDrivers())
);
}
|
Get all of the drivers that are actually available.
@return string[]
|
availableDrivers
|
php
|
illuminate/database
|
DatabaseManager.php
|
https://github.com/illuminate/database/blob/master/DatabaseManager.php
|
MIT
|
public function extend($name, callable $resolver)
{
$this->extensions[$name] = $resolver;
}
|
Register an extension connection resolver.
@param string $name
@param callable $resolver
@return void
|
extend
|
php
|
illuminate/database
|
DatabaseManager.php
|
https://github.com/illuminate/database/blob/master/DatabaseManager.php
|
MIT
|
public function forgetExtension($name)
{
unset($this->extensions[$name]);
}
|
Remove an extension connection resolver.
@param string $name
@return void
|
forgetExtension
|
php
|
illuminate/database
|
DatabaseManager.php
|
https://github.com/illuminate/database/blob/master/DatabaseManager.php
|
MIT
|
public function getConnections()
{
return $this->connections;
}
|
Return all of the created connections.
@return array<string, \Illuminate\Database\Connection>
|
getConnections
|
php
|
illuminate/database
|
DatabaseManager.php
|
https://github.com/illuminate/database/blob/master/DatabaseManager.php
|
MIT
|
public function setReconnector(callable $reconnector)
{
$this->reconnector = $reconnector;
}
|
Set the database reconnector callback.
@param callable $reconnector
@return void
|
setReconnector
|
php
|
illuminate/database
|
DatabaseManager.php
|
https://github.com/illuminate/database/blob/master/DatabaseManager.php
|
MIT
|
public function setApplication($app)
{
$this->app = $app;
return $this;
}
|
Set the application instance used by the manager.
@param \Illuminate\Contracts\Foundation\Application $app
@return $this
|
setApplication
|
php
|
illuminate/database
|
DatabaseManager.php
|
https://github.com/illuminate/database/blob/master/DatabaseManager.php
|
MIT
|
public function __call($method, $parameters)
{
if (static::hasMacro($method)) {
return $this->macroCall($method, $parameters);
}
return $this->connection()->$method(...$parameters);
}
|
Dynamically pass methods to the default connection.
@param string $method
@param array $parameters
@return mixed
|
__call
|
php
|
illuminate/database
|
DatabaseManager.php
|
https://github.com/illuminate/database/blob/master/DatabaseManager.php
|
MIT
|
public function boot()
{
Model::setConnectionResolver($this->app['db']);
Model::setEventDispatcher($this->app['events']);
}
|
Bootstrap the application events.
@return void
|
boot
|
php
|
illuminate/database
|
DatabaseServiceProvider.php
|
https://github.com/illuminate/database/blob/master/DatabaseServiceProvider.php
|
MIT
|
public function register()
{
Model::clearBootedModels();
$this->registerConnectionServices();
$this->registerFakerGenerator();
$this->registerQueueableEntityResolver();
}
|
Register the service provider.
@return void
|
register
|
php
|
illuminate/database
|
DatabaseServiceProvider.php
|
https://github.com/illuminate/database/blob/master/DatabaseServiceProvider.php
|
MIT
|
protected function registerConnectionServices()
{
// The connection factory is used to create the actual connection instances on
// the database. We will inject the factory into the manager so that it may
// make the connections while they are actually needed and not of before.
$this->app->singleton('db.factory', function ($app) {
return new ConnectionFactory($app);
});
// The database manager is used to resolve various connections, since multiple
// connections might be managed. It also implements the connection resolver
// interface which may be used by other components requiring connections.
$this->app->singleton('db', function ($app) {
return new DatabaseManager($app, $app['db.factory']);
});
$this->app->bind('db.connection', function ($app) {
return $app['db']->connection();
});
$this->app->bind('db.schema', function ($app) {
return $app['db']->connection()->getSchemaBuilder();
});
$this->app->singleton('db.transactions', function ($app) {
return new DatabaseTransactionsManager;
});
}
|
Register the primary database bindings.
@return void
|
registerConnectionServices
|
php
|
illuminate/database
|
DatabaseServiceProvider.php
|
https://github.com/illuminate/database/blob/master/DatabaseServiceProvider.php
|
MIT
|
protected function registerFakerGenerator()
{
$this->app->singleton(FakerGenerator::class, function ($app, $parameters) {
$locale = $parameters['locale'] ?? $app['config']->get('app.faker_locale', 'en_US');
if (! isset(static::$fakers[$locale])) {
static::$fakers[$locale] = FakerFactory::create($locale);
}
static::$fakers[$locale]->unique(true);
return static::$fakers[$locale];
});
}
|
Register the Faker Generator instance in the container.
@return void
|
registerFakerGenerator
|
php
|
illuminate/database
|
DatabaseServiceProvider.php
|
https://github.com/illuminate/database/blob/master/DatabaseServiceProvider.php
|
MIT
|
protected function registerQueueableEntityResolver()
{
$this->app->singleton(EntityResolver::class, function () {
return new QueueEntityResolver;
});
}
|
Register the queueable entity resolver implementation.
@return void
|
registerQueueableEntityResolver
|
php
|
illuminate/database
|
DatabaseServiceProvider.php
|
https://github.com/illuminate/database/blob/master/DatabaseServiceProvider.php
|
MIT
|
public function __construct($connection, $level, ?DatabaseTransactionRecord $parent = null)
{
$this->connection = $connection;
$this->level = $level;
$this->parent = $parent;
}
|
Create a new database transaction record instance.
@param string $connection
@param int $level
@param \Illuminate\Database\DatabaseTransactionRecord|null $parent
|
__construct
|
php
|
illuminate/database
|
DatabaseTransactionRecord.php
|
https://github.com/illuminate/database/blob/master/DatabaseTransactionRecord.php
|
MIT
|
public function addCallbackForRollback($callback)
{
$this->callbacksForRollback[] = $callback;
}
|
Register a callback to be executed after rollback.
@param callable $callback
@return void
|
addCallbackForRollback
|
php
|
illuminate/database
|
DatabaseTransactionRecord.php
|
https://github.com/illuminate/database/blob/master/DatabaseTransactionRecord.php
|
MIT
|
public function executeCallbacks()
{
foreach ($this->callbacks as $callback) {
$callback();
}
}
|
Execute all of the callbacks.
@return void
|
executeCallbacks
|
php
|
illuminate/database
|
DatabaseTransactionRecord.php
|
https://github.com/illuminate/database/blob/master/DatabaseTransactionRecord.php
|
MIT
|
public function executeCallbacksForRollback()
{
foreach ($this->callbacksForRollback as $callback) {
$callback();
}
}
|
Execute all of the callbacks for rollback.
@return void
|
executeCallbacksForRollback
|
php
|
illuminate/database
|
DatabaseTransactionRecord.php
|
https://github.com/illuminate/database/blob/master/DatabaseTransactionRecord.php
|
MIT
|
public function getCallbacks()
{
return $this->callbacks;
}
|
Get all of the callbacks.
@return array
|
getCallbacks
|
php
|
illuminate/database
|
DatabaseTransactionRecord.php
|
https://github.com/illuminate/database/blob/master/DatabaseTransactionRecord.php
|
MIT
|
public function getCallbacksForRollback()
{
return $this->callbacksForRollback;
}
|
Get all of the callbacks for rollback.
@return array
|
getCallbacksForRollback
|
php
|
illuminate/database
|
DatabaseTransactionRecord.php
|
https://github.com/illuminate/database/blob/master/DatabaseTransactionRecord.php
|
MIT
|
public function __construct()
{
$this->committedTransactions = new Collection;
$this->pendingTransactions = new Collection;
}
|
Create a new database transactions manager instance.
|
__construct
|
php
|
illuminate/database
|
DatabaseTransactionsManager.php
|
https://github.com/illuminate/database/blob/master/DatabaseTransactionsManager.php
|
MIT
|
public function begin($connection, $level)
{
$this->pendingTransactions->push(
$newTransaction = new DatabaseTransactionRecord(
$connection,
$level,
$this->currentTransaction[$connection] ?? null
)
);
$this->currentTransaction[$connection] = $newTransaction;
}
|
Start a new database transaction.
@param string $connection
@param int $level
@return void
|
begin
|
php
|
illuminate/database
|
DatabaseTransactionsManager.php
|
https://github.com/illuminate/database/blob/master/DatabaseTransactionsManager.php
|
MIT
|
public function rollback($connection, $newTransactionLevel)
{
if ($newTransactionLevel === 0) {
$this->removeAllTransactionsForConnection($connection);
} else {
$this->pendingTransactions = $this->pendingTransactions->reject(
fn ($transaction) => $transaction->connection == $connection &&
$transaction->level > $newTransactionLevel
)->values();
if ($this->currentTransaction) {
do {
$this->removeCommittedTransactionsThatAreChildrenOf($this->currentTransaction[$connection]);
$this->currentTransaction[$connection]->executeCallbacksForRollback();
$this->currentTransaction[$connection] = $this->currentTransaction[$connection]->parent;
} while (
isset($this->currentTransaction[$connection]) &&
$this->currentTransaction[$connection]->level > $newTransactionLevel
);
}
}
}
|
Rollback the active database transaction.
@param string $connection
@param int $newTransactionLevel
@return void
|
rollback
|
php
|
illuminate/database
|
DatabaseTransactionsManager.php
|
https://github.com/illuminate/database/blob/master/DatabaseTransactionsManager.php
|
MIT
|
protected function removeAllTransactionsForConnection($connection)
{
if ($this->currentTransaction) {
for ($currentTransaction = $this->currentTransaction[$connection]; isset($currentTransaction); $currentTransaction = $currentTransaction->parent) {
$currentTransaction->executeCallbacksForRollback();
}
}
$this->currentTransaction[$connection] = null;
$this->pendingTransactions = $this->pendingTransactions->reject(
fn ($transaction) => $transaction->connection == $connection
)->values();
$this->committedTransactions = $this->committedTransactions->reject(
fn ($transaction) => $transaction->connection == $connection
)->values();
}
|
Remove all pending, completed, and current transactions for the given connection name.
@param string $connection
@return void
|
removeAllTransactionsForConnection
|
php
|
illuminate/database
|
DatabaseTransactionsManager.php
|
https://github.com/illuminate/database/blob/master/DatabaseTransactionsManager.php
|
MIT
|
protected function removeCommittedTransactionsThatAreChildrenOf(DatabaseTransactionRecord $transaction)
{
[$removedTransactions, $this->committedTransactions] = $this->committedTransactions->partition(
fn ($committed) => $committed->connection == $transaction->connection &&
$committed->parent === $transaction
);
// There may be multiple deeply nested transactions that have already committed that we
// also need to remove. We will recurse down the children of all removed transaction
// instances until there are no more deeply nested child transactions for removal.
$removedTransactions->each(
fn ($transaction) => $this->removeCommittedTransactionsThatAreChildrenOf($transaction)
);
}
|
Remove all transactions that are children of the given transaction.
@param \Illuminate\Database\DatabaseTransactionRecord $transaction
@return void
|
removeCommittedTransactionsThatAreChildrenOf
|
php
|
illuminate/database
|
DatabaseTransactionsManager.php
|
https://github.com/illuminate/database/blob/master/DatabaseTransactionsManager.php
|
MIT
|
public function addCallback($callback)
{
if ($current = $this->callbackApplicableTransactions()->last()) {
return $current->addCallback($callback);
}
$callback();
}
|
Register a transaction callback.
@param callable $callback
@return void
|
addCallback
|
php
|
illuminate/database
|
DatabaseTransactionsManager.php
|
https://github.com/illuminate/database/blob/master/DatabaseTransactionsManager.php
|
MIT
|
public function addCallbackForRollback($callback)
{
if ($current = $this->callbackApplicableTransactions()->last()) {
return $current->addCallbackForRollback($callback);
}
}
|
Register a callback for transaction rollback.
@param callable $callback
@return void
|
addCallbackForRollback
|
php
|
illuminate/database
|
DatabaseTransactionsManager.php
|
https://github.com/illuminate/database/blob/master/DatabaseTransactionsManager.php
|
MIT
|
public function callbackApplicableTransactions()
{
return $this->pendingTransactions;
}
|
Get the transactions that are applicable to callbacks.
@return \Illuminate\Support\Collection<int, \Illuminate\Database\DatabaseTransactionRecord>
|
callbackApplicableTransactions
|
php
|
illuminate/database
|
DatabaseTransactionsManager.php
|
https://github.com/illuminate/database/blob/master/DatabaseTransactionsManager.php
|
MIT
|
public function getPendingTransactions()
{
return $this->pendingTransactions;
}
|
Get all of the pending transactions.
@return \Illuminate\Support\Collection
|
getPendingTransactions
|
php
|
illuminate/database
|
DatabaseTransactionsManager.php
|
https://github.com/illuminate/database/blob/master/DatabaseTransactionsManager.php
|
MIT
|
protected function causedByConcurrencyError(Throwable $e)
{
if ($e instanceof PDOException && ($e->getCode() === 40001 || $e->getCode() === '40001')) {
return true;
}
$message = $e->getMessage();
return Str::contains($message, [
'Deadlock found when trying to get lock',
'deadlock detected',
'The database file is locked',
'database is locked',
'database table is locked',
'A table in the database is locked',
'has been chosen as the deadlock victim',
'Lock wait timeout exceeded; try restarting transaction',
'WSREP detected deadlock/conflict and aborted the transaction. Try restarting the transaction',
]);
}
|
Determine if the given exception was caused by a concurrency error such as a deadlock or serialization failure.
@param \Throwable $e
@return bool
|
causedByConcurrencyError
|
php
|
illuminate/database
|
DetectsConcurrencyErrors.php
|
https://github.com/illuminate/database/blob/master/DetectsConcurrencyErrors.php
|
MIT
|
protected function causedByLostConnection(Throwable $e)
{
$message = $e->getMessage();
return Str::contains($message, [
'server has gone away',
'Server has gone away',
'no connection to the server',
'Lost connection',
'is dead or not enabled',
'Error while sending',
'decryption failed or bad record mac',
'server closed the connection unexpectedly',
'SSL connection has been closed unexpectedly',
'Error writing data to the connection',
'Resource deadlock avoided',
'Transaction() on null',
'child connection forced to terminate due to client_idle_limit',
'query_wait_timeout',
'reset by peer',
'Physical connection is not usable',
'TCP Provider: Error code 0x68',
'ORA-03114',
'Packets out of order. Expected',
'Adaptive Server connection failed',
'Communication link failure',
'connection is no longer usable',
'Login timeout expired',
'SQLSTATE[HY000] [2002] Connection refused',
'running with the --read-only option so it cannot execute this statement',
'The connection is broken and recovery is not possible. The connection is marked by the client driver as unrecoverable. No attempt was made to restore the connection.',
'SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Try again',
'SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name or service not known',
'SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo for',
'SQLSTATE[HY000]: General error: 7 SSL SYSCALL error: EOF detected',
'SQLSTATE[HY000] [2002] Connection timed out',
'SSL: Connection timed out',
'SQLSTATE[HY000]: General error: 1105 The last transaction was aborted due to Seamless Scaling. Please retry.',
'Temporary failure in name resolution',
'SQLSTATE[08S01]: Communication link failure',
'SQLSTATE[08006] [7] could not connect to server: Connection refused Is the server running on host',
'SQLSTATE[HY000]: General error: 7 SSL SYSCALL error: No route to host',
'The client was disconnected by the server because of inactivity. See wait_timeout and interactive_timeout for configuring this behavior.',
'SQLSTATE[08006] [7] could not translate host name',
'TCP Provider: Error code 0x274C',
'SQLSTATE[HY000] [2002] No such file or directory',
'SSL: Operation timed out',
'Reason: Server is in script upgrade mode. Only administrator can connect at this time.',
'Unknown $curl_error_code: 77',
'SSL: Handshake timed out',
'SSL error: sslv3 alert unexpected message',
'unrecognized SSL error code:',
'SQLSTATE[HY000] [1045] Access denied for user',
'SQLSTATE[HY000] [2002] No connection could be made because the target machine actively refused it',
'SQLSTATE[HY000] [2002] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond',
'SQLSTATE[HY000] [2002] Network is unreachable',
'SQLSTATE[HY000] [2002] The requested address is not valid in its context',
'SQLSTATE[HY000] [2002] A socket operation was attempted to an unreachable network',
'SQLSTATE[HY000] [2002] Operation now in progress',
'SQLSTATE[HY000] [2002] Operation in progress',
'SQLSTATE[HY000]: General error: 3989',
'went away',
'No such file or directory',
'server is shutting down',
'failed to connect to',
'Channel connection is closed',
'Connection lost',
'Broken pipe',
'SQLSTATE[25006]: Read only sql transaction: 7',
]);
}
|
Determine if the given exception was caused by a lost connection.
@param \Throwable $e
@return bool
|
causedByLostConnection
|
php
|
illuminate/database
|
DetectsLostConnections.php
|
https://github.com/illuminate/database/blob/master/DetectsLostConnections.php
|
MIT
|
public function __construct(Connection $connection)
{
$this->connection = $connection;
}
|
Create a new grammar instance.
@param \Illuminate\Database\Connection $connection
|
__construct
|
php
|
illuminate/database
|
Grammar.php
|
https://github.com/illuminate/database/blob/master/Grammar.php
|
MIT
|
public function wrapArray(array $values)
{
return array_map($this->wrap(...), $values);
}
|
Wrap an array of values.
@param array<\Illuminate\Contracts\Database\Query\Expression|string> $values
@return array<string>
|
wrapArray
|
php
|
illuminate/database
|
Grammar.php
|
https://github.com/illuminate/database/blob/master/Grammar.php
|
MIT
|
public function wrapTable($table, $prefix = null)
{
if ($this->isExpression($table)) {
return $this->getValue($table);
}
$prefix ??= $this->connection->getTablePrefix();
// If the table being wrapped has an alias we'll need to separate the pieces
// so we can prefix the table and then wrap each of the segments on their
// own and then join these both back together using the "as" connector.
if (stripos($table, ' as ') !== false) {
return $this->wrapAliasedTable($table, $prefix);
}
// If the table being wrapped has a custom schema name specified, we need to
// prefix the last segment as the table name then wrap each segment alone
// and eventually join them both back together using the dot connector.
if (str_contains($table, '.')) {
$table = substr_replace($table, '.'.$prefix, strrpos($table, '.'), 1);
return (new Collection(explode('.', $table)))
->map($this->wrapValue(...))
->implode('.');
}
return $this->wrapValue($prefix.$table);
}
|
Wrap a table in keyword identifiers.
@param \Illuminate\Contracts\Database\Query\Expression|string $table
@param string|null $prefix
@return string
|
wrapTable
|
php
|
illuminate/database
|
Grammar.php
|
https://github.com/illuminate/database/blob/master/Grammar.php
|
MIT
|
public function wrap($value)
{
if ($this->isExpression($value)) {
return $this->getValue($value);
}
// If the value being wrapped has a column alias we will need to separate out
// the pieces so we can wrap each of the segments of the expression on its
// own, and then join these both back together using the "as" connector.
if (stripos($value, ' as ') !== false) {
return $this->wrapAliasedValue($value);
}
// If the given value is a JSON selector we will wrap it differently than a
// traditional value. We will need to split this path and wrap each part
// wrapped, etc. Otherwise, we will simply wrap the value as a string.
if ($this->isJsonSelector($value)) {
return $this->wrapJsonSelector($value);
}
return $this->wrapSegments(explode('.', $value));
}
|
Wrap a value in keyword identifiers.
@param \Illuminate\Contracts\Database\Query\Expression|string $value
@return string
|
wrap
|
php
|
illuminate/database
|
Grammar.php
|
https://github.com/illuminate/database/blob/master/Grammar.php
|
MIT
|
protected function wrapAliasedValue($value)
{
$segments = preg_split('/\s+as\s+/i', $value);
return $this->wrap($segments[0]).' as '.$this->wrapValue($segments[1]);
}
|
Wrap a value that has an alias.
@param string $value
@return string
|
wrapAliasedValue
|
php
|
illuminate/database
|
Grammar.php
|
https://github.com/illuminate/database/blob/master/Grammar.php
|
MIT
|
protected function wrapAliasedTable($value, $prefix = null)
{
$segments = preg_split('/\s+as\s+/i', $value);
$prefix ??= $this->connection->getTablePrefix();
return $this->wrapTable($segments[0], $prefix).' as '.$this->wrapValue($prefix.$segments[1]);
}
|
Wrap a table that has an alias.
@param string $value
@param string|null $prefix
@return string
|
wrapAliasedTable
|
php
|
illuminate/database
|
Grammar.php
|
https://github.com/illuminate/database/blob/master/Grammar.php
|
MIT
|
protected function wrapSegments($segments)
{
return (new Collection($segments))->map(function ($segment, $key) use ($segments) {
return $key == 0 && count($segments) > 1
? $this->wrapTable($segment)
: $this->wrapValue($segment);
})->implode('.');
}
|
Wrap the given value segments.
@param list<string> $segments
@return string
|
wrapSegments
|
php
|
illuminate/database
|
Grammar.php
|
https://github.com/illuminate/database/blob/master/Grammar.php
|
MIT
|
protected function wrapValue($value)
{
if ($value !== '*') {
return '"'.str_replace('"', '""', $value).'"';
}
return $value;
}
|
Wrap a single string in keyword identifiers.
@param string $value
@return string
|
wrapValue
|
php
|
illuminate/database
|
Grammar.php
|
https://github.com/illuminate/database/blob/master/Grammar.php
|
MIT
|
protected function wrapJsonSelector($value)
{
throw new RuntimeException('This database engine does not support JSON operations.');
}
|
Wrap the given JSON selector.
@param string $value
@return string
@throws \RuntimeException
|
wrapJsonSelector
|
php
|
illuminate/database
|
Grammar.php
|
https://github.com/illuminate/database/blob/master/Grammar.php
|
MIT
|
protected function isJsonSelector($value)
{
return str_contains($value, '->');
}
|
Determine if the given string is a JSON selector.
@param string $value
@return bool
|
isJsonSelector
|
php
|
illuminate/database
|
Grammar.php
|
https://github.com/illuminate/database/blob/master/Grammar.php
|
MIT
|
public function parameterize(array $values)
{
return implode(', ', array_map($this->parameter(...), $values));
}
|
Create query parameter place-holders for an array.
@param array<mixed> $values
@return string
|
parameterize
|
php
|
illuminate/database
|
Grammar.php
|
https://github.com/illuminate/database/blob/master/Grammar.php
|
MIT
|
public function parameter($value)
{
return $this->isExpression($value) ? $this->getValue($value) : '?';
}
|
Get the appropriate query parameter place-holder for a value.
@param mixed $value
@return string
|
parameter
|
php
|
illuminate/database
|
Grammar.php
|
https://github.com/illuminate/database/blob/master/Grammar.php
|
MIT
|
public function quoteString($value)
{
if (is_array($value)) {
return implode(', ', array_map([$this, __FUNCTION__], $value));
}
return "'$value'";
}
|
Quote the given string literal.
@param string|array<string> $value
@return string
|
quoteString
|
php
|
illuminate/database
|
Grammar.php
|
https://github.com/illuminate/database/blob/master/Grammar.php
|
MIT
|
public function escape($value, $binary = false)
{
return $this->connection->escape($value, $binary);
}
|
Escapes a value for safe SQL embedding.
@param string|float|int|bool|null $value
@param bool $binary
@return string
|
escape
|
php
|
illuminate/database
|
Grammar.php
|
https://github.com/illuminate/database/blob/master/Grammar.php
|
MIT
|
public function isExpression($value)
{
return $value instanceof Expression;
}
|
Determine if the given value is a raw expression.
@param mixed $value
@return bool
|
isExpression
|
php
|
illuminate/database
|
Grammar.php
|
https://github.com/illuminate/database/blob/master/Grammar.php
|
MIT
|
public function getValue($expression)
{
if ($this->isExpression($expression)) {
return $this->getValue($expression->getValue($this));
}
return $expression;
}
|
Transforms expressions to their scalar types.
@param \Illuminate\Contracts\Database\Query\Expression|string|int|float $expression
@return string|int|float
|
getValue
|
php
|
illuminate/database
|
Grammar.php
|
https://github.com/illuminate/database/blob/master/Grammar.php
|
MIT
|
public function getDateFormat()
{
return 'Y-m-d H:i:s';
}
|
Get the format for database stored dates.
@return string
|
getDateFormat
|
php
|
illuminate/database
|
Grammar.php
|
https://github.com/illuminate/database/blob/master/Grammar.php
|
MIT
|
public function getTablePrefix()
{
return $this->connection->getTablePrefix();
}
|
Get the grammar's table prefix.
@deprecated Use DB::getTablePrefix()
@return string
|
getTablePrefix
|
php
|
illuminate/database
|
Grammar.php
|
https://github.com/illuminate/database/blob/master/Grammar.php
|
MIT
|
public function setTablePrefix($prefix)
{
$this->connection->setTablePrefix($prefix);
return $this;
}
|
Set the grammar's table prefix.
@deprecated Use DB::setTablePrefix()
@param string $prefix
@return $this
|
setTablePrefix
|
php
|
illuminate/database
|
Grammar.php
|
https://github.com/illuminate/database/blob/master/Grammar.php
|
MIT
|
public function __construct($model, $relation)
{
$class = get_class($model);
parent::__construct("Attempted to lazy load [{$relation}] on model [{$class}] but lazy loading is disabled.");
$this->model = $class;
$this->relation = $relation;
}
|
Create a new exception instance.
@param object $model
@param string $relation
|
__construct
|
php
|
illuminate/database
|
LazyLoadingViolationException.php
|
https://github.com/illuminate/database/blob/master/LazyLoadingViolationException.php
|
MIT
|
public function isMaria()
{
return true;
}
|
Determine if the connected database is a MariaDB database.
@return bool
|
isMaria
|
php
|
illuminate/database
|
MariaDbConnection.php
|
https://github.com/illuminate/database/blob/master/MariaDbConnection.php
|
MIT
|
public function getServerVersion(): string
{
return Str::between(parent::getServerVersion(), '5.5.5-', '-MariaDB');
}
|
Get the server version for the connection.
@return string
|
getServerVersion
|
php
|
illuminate/database
|
MariaDbConnection.php
|
https://github.com/illuminate/database/blob/master/MariaDbConnection.php
|
MIT
|
protected function getDefaultQueryGrammar()
{
return new QueryGrammar($this);
}
|
Get the default query grammar instance.
@return \Illuminate\Database\Query\Grammars\MariaDbGrammar
|
getDefaultQueryGrammar
|
php
|
illuminate/database
|
MariaDbConnection.php
|
https://github.com/illuminate/database/blob/master/MariaDbConnection.php
|
MIT
|
public function getSchemaBuilder()
{
if (is_null($this->schemaGrammar)) {
$this->useDefaultSchemaGrammar();
}
return new MariaDbBuilder($this);
}
|
Get a schema builder instance for the connection.
@return \Illuminate\Database\Schema\MariaDbBuilder
|
getSchemaBuilder
|
php
|
illuminate/database
|
MariaDbConnection.php
|
https://github.com/illuminate/database/blob/master/MariaDbConnection.php
|
MIT
|
protected function getDefaultSchemaGrammar()
{
return new SchemaGrammar($this);
}
|
Get the default schema grammar instance.
@return \Illuminate\Database\Schema\Grammars\MariaDbGrammar
|
getDefaultSchemaGrammar
|
php
|
illuminate/database
|
MariaDbConnection.php
|
https://github.com/illuminate/database/blob/master/MariaDbConnection.php
|
MIT
|
public function getSchemaState(?Filesystem $files = null, ?callable $processFactory = null)
{
return new MariaDbSchemaState($this, $files, $processFactory);
}
|
Get the schema state for the connection.
@param \Illuminate\Filesystem\Filesystem|null $files
@param callable|null $processFactory
@return \Illuminate\Database\Schema\MariaDbSchemaState
|
getSchemaState
|
php
|
illuminate/database
|
MariaDbConnection.php
|
https://github.com/illuminate/database/blob/master/MariaDbConnection.php
|
MIT
|
protected function getDefaultPostProcessor()
{
return new MariaDbProcessor;
}
|
Get the default post processor instance.
@return \Illuminate\Database\Query\Processors\MariaDbProcessor
|
getDefaultPostProcessor
|
php
|
illuminate/database
|
MariaDbConnection.php
|
https://github.com/illuminate/database/blob/master/MariaDbConnection.php
|
MIT
|
public function register()
{
$this->registerRepository();
$this->registerMigrator();
$this->registerCreator();
$this->registerCommands($this->commands);
}
|
Register the service provider.
@return void
|
register
|
php
|
illuminate/database
|
MigrationServiceProvider.php
|
https://github.com/illuminate/database/blob/master/MigrationServiceProvider.php
|
MIT
|
protected function registerRepository()
{
$this->app->singleton('migration.repository', function ($app) {
$migrations = $app['config']['database.migrations'];
$table = is_array($migrations) ? ($migrations['table'] ?? null) : $migrations;
return new DatabaseMigrationRepository($app['db'], $table);
});
}
|
Register the migration repository service.
@return void
|
registerRepository
|
php
|
illuminate/database
|
MigrationServiceProvider.php
|
https://github.com/illuminate/database/blob/master/MigrationServiceProvider.php
|
MIT
|
protected function registerMigrator()
{
// The migrator is responsible for actually running and rollback the migration
// files in the application. We'll pass in our database connection resolver
// so the migrator can resolve any of these connections when it needs to.
$this->app->singleton('migrator', function ($app) {
$repository = $app['migration.repository'];
return new Migrator($repository, $app['db'], $app['files'], $app['events']);
});
$this->app->bind(Migrator::class, fn ($app) => $app['migrator']);
}
|
Register the migrator service.
@return void
|
registerMigrator
|
php
|
illuminate/database
|
MigrationServiceProvider.php
|
https://github.com/illuminate/database/blob/master/MigrationServiceProvider.php
|
MIT
|
protected function registerCreator()
{
$this->app->singleton('migration.creator', function ($app) {
return new MigrationCreator($app['files'], $app->basePath('stubs'));
});
}
|
Register the migration creator.
@return void
|
registerCreator
|
php
|
illuminate/database
|
MigrationServiceProvider.php
|
https://github.com/illuminate/database/blob/master/MigrationServiceProvider.php
|
MIT
|
protected function registerCommands(array $commands)
{
foreach (array_keys($commands) as $command) {
$this->{"register{$command}Command"}();
}
$this->commands(array_values($commands));
}
|
Register the given commands.
@param array $commands
@return void
|
registerCommands
|
php
|
illuminate/database
|
MigrationServiceProvider.php
|
https://github.com/illuminate/database/blob/master/MigrationServiceProvider.php
|
MIT
|
public function provides()
{
return array_merge([
'migrator', 'migration.repository', 'migration.creator', Migrator::class,
], array_values($this->commands));
}
|
Get the services provided by the provider.
@return array
|
provides
|
php
|
illuminate/database
|
MigrationServiceProvider.php
|
https://github.com/illuminate/database/blob/master/MigrationServiceProvider.php
|
MIT
|
public function __construct($count, $code = 0, $previous = null)
{
$this->count = $count;
parent::__construct("$count records were found.", $code, $previous);
}
|
Create a new exception instance.
@param int $count
@param int $code
@param \Throwable|null $previous
|
__construct
|
php
|
illuminate/database
|
MultipleRecordsFoundException.php
|
https://github.com/illuminate/database/blob/master/MultipleRecordsFoundException.php
|
MIT
|
public function getCount()
{
return $this->count;
}
|
Get the number of records found.
@return int
|
getCount
|
php
|
illuminate/database
|
MultipleRecordsFoundException.php
|
https://github.com/illuminate/database/blob/master/MultipleRecordsFoundException.php
|
MIT
|
public function insert($query, $bindings = [], $sequence = null)
{
return $this->run($query, $bindings, function ($query, $bindings) use ($sequence) {
if ($this->pretending()) {
return true;
}
$statement = $this->getPdo()->prepare($query);
$this->bindValues($statement, $this->prepareBindings($bindings));
$this->recordsHaveBeenModified();
$result = $statement->execute();
$this->lastInsertId = $this->getPdo()->lastInsertId($sequence);
return $result;
});
}
|
Run an insert statement against the database.
@param string $query
@param array $bindings
@param string|null $sequence
@return bool
|
insert
|
php
|
illuminate/database
|
MySqlConnection.php
|
https://github.com/illuminate/database/blob/master/MySqlConnection.php
|
MIT
|
protected function escapeBinary($value)
{
$hex = bin2hex($value);
return "x'{$hex}'";
}
|
Escape a binary value for safe SQL embedding.
@param string $value
@return string
|
escapeBinary
|
php
|
illuminate/database
|
MySqlConnection.php
|
https://github.com/illuminate/database/blob/master/MySqlConnection.php
|
MIT
|
protected function isUniqueConstraintError(Exception $exception)
{
return boolval(preg_match('#Integrity constraint violation: 1062#i', $exception->getMessage()));
}
|
Determine if the given database exception was caused by a unique constraint violation.
@param \Exception $exception
@return bool
|
isUniqueConstraintError
|
php
|
illuminate/database
|
MySqlConnection.php
|
https://github.com/illuminate/database/blob/master/MySqlConnection.php
|
MIT
|
public function getLastInsertId()
{
return $this->lastInsertId;
}
|
Get the connection's last insert ID.
@return string|int|null
|
getLastInsertId
|
php
|
illuminate/database
|
MySqlConnection.php
|
https://github.com/illuminate/database/blob/master/MySqlConnection.php
|
MIT
|
public function isMaria()
{
return str_contains($this->getPdo()->getAttribute(PDO::ATTR_SERVER_VERSION), 'MariaDB');
}
|
Determine if the connected database is a MariaDB database.
@return bool
|
isMaria
|
php
|
illuminate/database
|
MySqlConnection.php
|
https://github.com/illuminate/database/blob/master/MySqlConnection.php
|
MIT
|
public function getServerVersion(): string
{
return str_contains($version = parent::getServerVersion(), 'MariaDB')
? Str::between($version, '5.5.5-', '-MariaDB')
: $version;
}
|
Get the server version for the connection.
@return string
|
getServerVersion
|
php
|
illuminate/database
|
MySqlConnection.php
|
https://github.com/illuminate/database/blob/master/MySqlConnection.php
|
MIT
|
protected function getDefaultQueryGrammar()
{
return new QueryGrammar($this);
}
|
Get the default query grammar instance.
@return \Illuminate\Database\Query\Grammars\MySqlGrammar
|
getDefaultQueryGrammar
|
php
|
illuminate/database
|
MySqlConnection.php
|
https://github.com/illuminate/database/blob/master/MySqlConnection.php
|
MIT
|
public function getSchemaBuilder()
{
if (is_null($this->schemaGrammar)) {
$this->useDefaultSchemaGrammar();
}
return new MySqlBuilder($this);
}
|
Get a schema builder instance for the connection.
@return \Illuminate\Database\Schema\MySqlBuilder
|
getSchemaBuilder
|
php
|
illuminate/database
|
MySqlConnection.php
|
https://github.com/illuminate/database/blob/master/MySqlConnection.php
|
MIT
|
protected function getDefaultSchemaGrammar()
{
return new SchemaGrammar($this);
}
|
Get the default schema grammar instance.
@return \Illuminate\Database\Schema\Grammars\MySqlGrammar
|
getDefaultSchemaGrammar
|
php
|
illuminate/database
|
MySqlConnection.php
|
https://github.com/illuminate/database/blob/master/MySqlConnection.php
|
MIT
|
public function getSchemaState(?Filesystem $files = null, ?callable $processFactory = null)
{
return new MySqlSchemaState($this, $files, $processFactory);
}
|
Get the schema state for the connection.
@param \Illuminate\Filesystem\Filesystem|null $files
@param callable|null $processFactory
@return \Illuminate\Database\Schema\MySqlSchemaState
|
getSchemaState
|
php
|
illuminate/database
|
MySqlConnection.php
|
https://github.com/illuminate/database/blob/master/MySqlConnection.php
|
MIT
|
protected function getDefaultPostProcessor()
{
return new MySqlProcessor;
}
|
Get the default post processor instance.
@return \Illuminate\Database\Query\Processors\MySqlProcessor
|
getDefaultPostProcessor
|
php
|
illuminate/database
|
MySqlConnection.php
|
https://github.com/illuminate/database/blob/master/MySqlConnection.php
|
MIT
|
protected function escapeBinary($value)
{
$hex = bin2hex($value);
return "'\x{$hex}'::bytea";
}
|
Escape a binary value for safe SQL embedding.
@param string $value
@return string
|
escapeBinary
|
php
|
illuminate/database
|
PostgresConnection.php
|
https://github.com/illuminate/database/blob/master/PostgresConnection.php
|
MIT
|
protected function escapeBool($value)
{
return $value ? 'true' : 'false';
}
|
Escape a bool value for safe SQL embedding.
@param bool $value
@return string
|
escapeBool
|
php
|
illuminate/database
|
PostgresConnection.php
|
https://github.com/illuminate/database/blob/master/PostgresConnection.php
|
MIT
|
protected function isUniqueConstraintError(Exception $exception)
{
return '23505' === $exception->getCode();
}
|
Determine if the given database exception was caused by a unique constraint violation.
@param \Exception $exception
@return bool
|
isUniqueConstraintError
|
php
|
illuminate/database
|
PostgresConnection.php
|
https://github.com/illuminate/database/blob/master/PostgresConnection.php
|
MIT
|
protected function getDefaultQueryGrammar()
{
return new QueryGrammar($this);
}
|
Get the default query grammar instance.
@return \Illuminate\Database\Query\Grammars\PostgresGrammar
|
getDefaultQueryGrammar
|
php
|
illuminate/database
|
PostgresConnection.php
|
https://github.com/illuminate/database/blob/master/PostgresConnection.php
|
MIT
|
public function getSchemaBuilder()
{
if (is_null($this->schemaGrammar)) {
$this->useDefaultSchemaGrammar();
}
return new PostgresBuilder($this);
}
|
Get a schema builder instance for the connection.
@return \Illuminate\Database\Schema\PostgresBuilder
|
getSchemaBuilder
|
php
|
illuminate/database
|
PostgresConnection.php
|
https://github.com/illuminate/database/blob/master/PostgresConnection.php
|
MIT
|
protected function getDefaultSchemaGrammar()
{
return new SchemaGrammar($this);
}
|
Get the default schema grammar instance.
@return \Illuminate\Database\Schema\Grammars\PostgresGrammar
|
getDefaultSchemaGrammar
|
php
|
illuminate/database
|
PostgresConnection.php
|
https://github.com/illuminate/database/blob/master/PostgresConnection.php
|
MIT
|
public function getSchemaState(?Filesystem $files = null, ?callable $processFactory = null)
{
return new PostgresSchemaState($this, $files, $processFactory);
}
|
Get the schema state for the connection.
@param \Illuminate\Filesystem\Filesystem|null $files
@param callable|null $processFactory
@return \Illuminate\Database\Schema\PostgresSchemaState
|
getSchemaState
|
php
|
illuminate/database
|
PostgresConnection.php
|
https://github.com/illuminate/database/blob/master/PostgresConnection.php
|
MIT
|
protected function getDefaultPostProcessor()
{
return new PostgresProcessor;
}
|
Get the default post processor instance.
@return \Illuminate\Database\Query\Processors\PostgresProcessor
|
getDefaultPostProcessor
|
php
|
illuminate/database
|
PostgresConnection.php
|
https://github.com/illuminate/database/blob/master/PostgresConnection.php
|
MIT
|
public function __construct($connectionName, $sql, array $bindings, Throwable $previous)
{
parent::__construct('', 0, $previous);
$this->connectionName = $connectionName;
$this->sql = $sql;
$this->bindings = $bindings;
$this->code = $previous->getCode();
$this->message = $this->formatMessage($connectionName, $sql, $bindings, $previous);
if ($previous instanceof PDOException) {
$this->errorInfo = $previous->errorInfo;
}
}
|
Create a new query exception instance.
@param string $connectionName
@param string $sql
@param array $bindings
@param \Throwable $previous
|
__construct
|
php
|
illuminate/database
|
QueryException.php
|
https://github.com/illuminate/database/blob/master/QueryException.php
|
MIT
|
protected function formatMessage($connectionName, $sql, $bindings, Throwable $previous)
{
return $previous->getMessage().' (Connection: '.$connectionName.', SQL: '.Str::replaceArray('?', $bindings, $sql).')';
}
|
Format the SQL error message.
@param string $connectionName
@param string $sql
@param array $bindings
@param \Throwable $previous
@return string
|
formatMessage
|
php
|
illuminate/database
|
QueryException.php
|
https://github.com/illuminate/database/blob/master/QueryException.php
|
MIT
|
public function getConnectionName()
{
return $this->connectionName;
}
|
Get the connection name for the query.
@return string
|
getConnectionName
|
php
|
illuminate/database
|
QueryException.php
|
https://github.com/illuminate/database/blob/master/QueryException.php
|
MIT
|
public function getSql()
{
return $this->sql;
}
|
Get the SQL for the query.
@return string
|
getSql
|
php
|
illuminate/database
|
QueryException.php
|
https://github.com/illuminate/database/blob/master/QueryException.php
|
MIT
|
public function getRawSql(): string
{
return DB::connection($this->getConnectionName())
->getQueryGrammar()
->substituteBindingsIntoRawSql($this->getSql(), $this->getBindings());
}
|
Get the raw SQL representation of the query with embedded bindings.
|
getRawSql
|
php
|
illuminate/database
|
QueryException.php
|
https://github.com/illuminate/database/blob/master/QueryException.php
|
MIT
|
public function getBindings()
{
return $this->bindings;
}
|
Get the bindings for the query.
@return array
|
getBindings
|
php
|
illuminate/database
|
QueryException.php
|
https://github.com/illuminate/database/blob/master/QueryException.php
|
MIT
|
public function call($class, $silent = false, array $parameters = [])
{
$classes = Arr::wrap($class);
foreach ($classes as $class) {
$seeder = $this->resolve($class);
$name = get_class($seeder);
if ($silent === false && isset($this->command)) {
with(new TwoColumnDetail($this->command->getOutput()))->render(
$name,
'<fg=yellow;options=bold>RUNNING</>'
);
}
$startTime = microtime(true);
$seeder->__invoke($parameters);
if ($silent === false && isset($this->command)) {
$runTime = number_format((microtime(true) - $startTime) * 1000);
with(new TwoColumnDetail($this->command->getOutput()))->render(
$name,
"<fg=gray>$runTime ms</> <fg=green;options=bold>DONE</>"
);
$this->command->getOutput()->writeln('');
}
static::$called[] = $class;
}
return $this;
}
|
Run the given seeder class.
@param array|string $class
@param bool $silent
@param array $parameters
@return $this
|
call
|
php
|
illuminate/database
|
Seeder.php
|
https://github.com/illuminate/database/blob/master/Seeder.php
|
MIT
|
public function callWith($class, array $parameters = [])
{
$this->call($class, false, $parameters);
}
|
Run the given seeder class.
@param array|string $class
@param array $parameters
@return void
|
callWith
|
php
|
illuminate/database
|
Seeder.php
|
https://github.com/illuminate/database/blob/master/Seeder.php
|
MIT
|
public function callSilent($class, array $parameters = [])
{
$this->call($class, true, $parameters);
}
|
Silently run the given seeder class.
@param array|string $class
@param array $parameters
@return void
|
callSilent
|
php
|
illuminate/database
|
Seeder.php
|
https://github.com/illuminate/database/blob/master/Seeder.php
|
MIT
|
public function callOnce($class, $silent = false, array $parameters = [])
{
$classes = Arr::wrap($class);
foreach ($classes as $class) {
if (in_array($class, static::$called)) {
continue;
}
$this->call($class, $silent, $parameters);
}
}
|
Run the given seeder class once.
@param array|string $class
@param bool $silent
@return void
|
callOnce
|
php
|
illuminate/database
|
Seeder.php
|
https://github.com/illuminate/database/blob/master/Seeder.php
|
MIT
|
protected function resolve($class)
{
if (isset($this->container)) {
$instance = $this->container->make($class);
$instance->setContainer($this->container);
} else {
$instance = new $class;
}
if (isset($this->command)) {
$instance->setCommand($this->command);
}
return $instance;
}
|
Resolve an instance of the given seeder class.
@param string $class
@return \Illuminate\Database\Seeder
|
resolve
|
php
|
illuminate/database
|
Seeder.php
|
https://github.com/illuminate/database/blob/master/Seeder.php
|
MIT
|
public function setContainer(Container $container)
{
$this->container = $container;
return $this;
}
|
Set the IoC container instance.
@param \Illuminate\Contracts\Container\Container $container
@return $this
|
setContainer
|
php
|
illuminate/database
|
Seeder.php
|
https://github.com/illuminate/database/blob/master/Seeder.php
|
MIT
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.