跳转到内容

Phalcon 数据库

注意

所有类都以前缀命名Phalcon

Db\Adapter\AbstractAdapterAbstract

GitHub上的源码

  • 命名空间

    • Phalcon\Db\Adapter
  • 使用

    • Phalcon\Db\ColumnInterface
    • Phalcon\Db\DialectInterface
    • Phalcon\Db\Enum
    • Phalcon\Db\Exception
    • Phalcon\Db\Index
    • Phalcon\Db\IndexInterface
    • Phalcon\Db\RawValue
    • Phalcon\Db\Reference
    • Phalcon\Db\ReferenceInterface
    • Phalcon\Events\EventsAwareInterface
    • Phalcon\Events\ManagerInterface
  • 继承

  • 实现

    • AdapterInterface
    • EventsAwareInterface

Phalcon\Db\Adapter 适配器的基类。

此类及其相关类为 Phalcon 框架提供了简单的 SQL 数据库接口。Phalcon\Db 是你用来将 PHP 应用程序连接到关系型数据库管理系统(RDBMS)的基本类。每种品牌的关系型数据库都有不同的适配器类。

此组件旨在执行低级数据库操作。如果希望使用更高级别的抽象与数据库交互,请使用 Phalcon\Mvc\Model。

Phalcon\Db\AbstractDb 是一个抽象类。你只能将其与像 Phalcon\Db\Adapter\Pdo 这样的数据库适配器一起使用。

use Phalcon\Db;
use Phalcon\Db\Exception;
use Phalcon\Db\Adapter\Pdo\Mysql as MysqlConnection;

try {
    $connection = new MysqlConnection(
        [
            "host"     => "192.168.0.11",
            "username" => "sigma",
            "password" => "secret",
            "dbname"   => "blog",
            "port"     => "3306",
        ]
    );

    $result = $connection->query(
        "SELECTFROM co_invoices LIMIT 5"
    );

    $result->setFetchMode(Enum::FETCH_NUM);

    while ($invoice = $result->fetch()) {
        print_r($invoice);
    }
} catch (Exception $e) {
    echo $e->getMessage(), PHP_EOL;
}

属性

/**
 * Connection ID
 *
 * @var int
 */
protected static $connectionConsecutive = ;

/**
 * Active connection ID
 *
 * @var int
 */
protected $connectionId;

/**
 * Descriptor used to connect to a database
 *
 * @var array
 */
protected $descriptor;

/**
 * Dialect instance
 *
 * @var object
 */
protected $dialect;

/**
 * Name of the dialect used
 *
 * @var string
 */
protected $dialectType;

/**
 * Event Manager
 *
 * @var ManagerInterface|null
 */
protected $eventsManager;

/**
 * The real SQL statement - what was executed
 *
 * @var string
 */
protected $realSqlStatement;

/**
 * Active SQL Bind Types
 *
 * @var array
 */
protected $sqlBindTypes;

/**
 * Active SQL Statement
 *
 * @var string
 */
protected $sqlStatement;

/**
 * Active SQL bound parameter variables
 *
 * @var array
 */
protected $sqlVariables;

/**
 * Current transaction level
 *
 * @var int
 */
protected $transactionLevel = ;

/**
 * Whether the database supports transactions with save points
 *
 * @var bool
 */
protected $transactionsWithSavepoints = false;

/**
 * Type of database system the adapter is used for
 *
 * @var string
 */
protected $type;

方法

public function __construct( array $descriptor );
Phalcon\Db\Adapter 构造函数

public function addColumn( string $tableName, string $schemaName, ColumnInterface $column ): bool;
向表中添加一列

public function addForeignKey( string $tableName, string $schemaName, ReferenceInterface $reference ): bool;
向表中添加外键

public function addIndex( string $tableName, string $schemaName, IndexInterface $index ): bool;
向表中添加索引

public function addPrimaryKey( string $tableName, string $schemaName, IndexInterface $index ): bool;
向表中添加主键

public function createSavepoint( string $name ): bool;
创建一个新的保存点

public function createTable( string $tableName, string $schemaName, array $definition ): bool;
创建一个表

public function createView( string $viewName, array $definition, string $schemaName = null ): bool;
创建视图

public function delete( mixed $table, string $whereCondition = null, array $placeholders = [], array $dataTypes = [] ): bool;
使用自定义 RBDM SQL 语法从表中删除数据

// Deleting existing robot
$success = $connection->delete(
    "robots",
    "id = 101"
);

// Next SQL sentence is generated
DELETE FROM `robots` WHERE `id` = 101

public function describeIndexes( string $table, string $schema = null ): IndexInterface[];
列出表的索引

print_r(
    $connection->describeIndexes("robots_parts")
);

public function describeReferences( string $table, string $schema = null ): ReferenceInterface[];
列出表的引用

print_r(
    $connection->describeReferences("robots_parts")
);

public function dropColumn( string $tableName, string $schemaName, string $columnName ): bool;
从表中删除一列

public function dropForeignKey( string $tableName, string $schemaName, string $referenceName ): bool;
从表中删除外键

public function dropIndex( string $tableName, string $schemaName, mixed $indexName ): bool;
从表中删除索引

public function dropPrimaryKey( string $tableName, string $schemaName ): bool;
删除表的主键

public function dropTable( string $tableName, string $schemaName = null, bool $ifExists = bool ): bool;
从模式/数据库中删除表

public function dropView( string $viewName, string $schemaName = null, bool $ifExists = bool ): bool;
删除视图

public function escapeIdentifier( mixed $identifier ): string;
转义列/表/模式名称

$escapedTable = $connection->escapeIdentifier(
    "robots"
);

$escapedTable = $connection->escapeIdentifier(
    [
        "store",
        "robots",
    ]
);

public function fetchAll( string $sqlQuery, int $fetchMode = static-constant-access, array $bindParams = [], array $bindTypes = [] ): array;
将查询结果全部转储为数组

// Getting all robots with associative indexes only
$robots = $connection->fetchAll(
    "SELECTFROM robots",
    \Phalcon\Db\Enum::FETCH_ASSOC
);

foreach ($robots as $robot) {
    print_r($robot);
}

 // Getting all robots that contains word "robot" withing the name
$robots = $connection->fetchAll(
    "SELECTFROM robots WHERE name LIKE :name",
    \Phalcon\Db\Enum::FETCH_ASSOC,
    [
        "name" => "%robot%",
    ]
);
foreach($robots as $robot) {
    print_r($robot);
}

public function fetchColumn( string $sqlQuery, array $placeholders = [], mixed $column = int ): string | bool;
返回 SQL 查询结果第一行的第 n 个字段

// Getting count of robots
$robotsCount = $connection->fetchColumn("SELECT count(*) FROM robots");
print_r($robotsCount);

// Getting name of last edited robot
$robot = $connection->fetchColumn(
    "SELECT id, name FROM robots ORDER BY modified DESC",
    1
);
print_r($robot);

public function fetchOne( string $sqlQuery, mixed $fetchMode = static-constant-access, array $bindParams = [], array $bindTypes = [] ): array;
返回 SQL 查询结果的第一行

// Getting first robot
$robot = $connection->fetchOne("SELECTFROM robots");
print_r($robot);

// Getting first robot with associative indexes only
$robot = $connection->fetchOne(
    "SELECTFROM robots",
    \Phalcon\Db\Enum::FETCH_ASSOC
);
print_r($robot);

public function forUpdate( string $sqlQuery ): string;
返回带有FOR UPDATE子句修改后的SQL

public function getColumnDefinition( ColumnInterface $column ): string;
返回列的SQL列定义

public function getColumnList( mixed $columnList ): string;
获取列列表

public function getConnectionId(): string;
获取活动连接的唯一标识符

public function getDefaultIdValue(): RawValue;
返回用于插入到标识列中的默认标识值

// Inserting a new robot with a valid default value for the column 'id'
$success = $connection->insert(
    "robots",
    [
        $connection->getDefaultIdValue(),
        "Astro Boy",
        1952,
    ],
    [
        "id",
        "name",
        "year",
    ]
);

public function getDefaultValue(): RawValue;
返回让RDBMS使用表定义中声明的默认值的默认值

// Inserting a new robot with a valid default value for the column 'year'
$success = $connection->insert(
    "robots",
    [
        "Astro Boy",
        $connection->getDefaultValue()
    ],
    [
        "name",
        "year",
    ]
);

@todo 如果适配器不支持,则返回 NULL

public function getDescriptor(): array;
返回用于连接到活动数据库的描述符

public function getDialect(): DialectInterface;
返回内部方言实例

public function getDialectType(): string;
使用的方言名称

public function getEventsManager(): ManagerInterface | null;
返回内部事件管理器

public function getNestedTransactionSavepointName(): string;
返回嵌套事务要用的保存点名称

public function getRealSQLStatement(): string;
对象中的活动 SQL 语句,未替换绑定参数

public function getSQLBindTypes(): array;
对象中的当前SQL语句

public function getSQLStatement(): string;
对象中的当前SQL语句

public function getSQLVariables(): array;
对象中的活动 SQL 变量

public function getType(): string;
适配器所用于的数据库系统类型

public function insert( string $table, array $values, mixed $fields = null, mixed $dataTypes = null ): bool;
使用自定义 RDBMS SQL 语法向表插入数据

// Inserting a new robot
$success = $connection->insert(
    "robots",
    ["Astro Boy", 1952],
    ["name", "year"]
);

// Next SQL sentence is sent to the database system
INSERT INTO `robots` (`name`, `year`) VALUES ("Astro boy", 1952);

public function insertAsDict( string $table, mixed $data, mixed $dataTypes = null ): bool;
使用自定义 RBDM SQL 语法向表插入数据

// Inserting a new robot
$success = $connection->insertAsDict(
    "robots",
    [
        "name" => "Astro Boy",
        "year" => 1952,
    ]
);

// Next SQL sentence is sent to the database system
INSERT INTO `robots` (`name`, `year`) VALUES ("Astro boy", 1952);

public function isNestedTransactionsWithSavepoints(): bool;
返回是否嵌套事务应使用保存点

public function limit( string $sqlQuery, int $number ): string;
将 LIMIT 子句附加到 $sqlQuery 参数

echo $connection->limit("SELECTFROM robots", 5);

public function listTables( string $schemaName = null ): array;
列出数据库中的所有表

print_r(
    $connection->listTables("blog")
);

public function listViews( string $schemaName = null ): array;
列出数据库中的所有视图

print_r(
    $connection->listViews("blog")
);

public function modifyColumn( string $tableName, string $schemaName, ColumnInterface $column, ColumnInterface $currentColumn = null ): bool;
基于定义修改表列

public function releaseSavepoint( string $name ): bool;
释放给定的保存点

public function rollbackSavepoint( string $name ): bool;
回滚给定的保存点

public function setDialect( DialectInterface $dialect );
设置用于生成 SQL 的方言

public function setEventsManager( ManagerInterface $eventsManager ): void;
设置事件管理器

public function setNestedTransactionsWithSavepoints( bool $nestedTransactionsWithSavepoints ): AdapterInterface;
设置是否嵌套事务应使用保存点

public static function setup( array $options ): void;
启用/禁用数据库组件中的选项

public function sharedLock( string $sqlQuery ): string;
返回带有LOCK IN SHARE MODE子句修改后的SQL

public function supportSequences(): bool;
检查数据库系统是否需要序列来生成自增数值

public function supportsDefaultValue(): bool;
检查数据库系统是否支持 DEFAULT 关键字(SQLite 不支持)

@废弃 将在下一个版本中移除

public function tableExists( string $tableName, string $schemaName = null ): bool;
生成检查模式.表是否存在的SQL

var_dump(
    $connection->tableExists("blog", "posts")
);

public function tableOptions( string $tableName, string $schemaName = null ): array;
获取表的创建选项

print_r(
    $connection->tableOptions("robots")
);

public function update( string $table, mixed $fields, mixed $values, mixed $whereCondition = null, mixed $dataTypes = null ): bool;
使用自定义 RBDM SQL 语法更新表中的数据

// Updating existing robot
$success = $connection->update(
    "robots",
    ["name"],
    ["New Astro Boy"],
    "id = 101"
);

// Next SQL sentence is sent to the database system
UPDATE `robots` SET `name` = "Astro boy" WHERE id = 101

// Updating existing robot with array condition and $dataTypes
$success = $connection->update(
    "robots",
    ["name"],
    ["New Astro Boy"],
    [
        "conditions" => "id = ?",
        "bind"       => [$some_unsafe_id],
        "bindTypes"  => [PDO::PARAM_INT], // use only if you use $dataTypes param
    ],
    [
        PDO::PARAM_STR
    ]
);

警告!如果 $whereCondition 是字符串,则不会进行转义。

public function updateAsDict( string $table, mixed $data, mixed $whereCondition = null, mixed $dataTypes = null ): bool;
使用自定义 RBDM SQL 语法更新表中的数据,另一种更方便的语法

// Updating existing robot
$success = $connection->updateAsDict(
    "robots",
    [
        "name" => "New Astro Boy",
    ],
    "id = 101"
);

// Next SQL sentence is sent to the database system
UPDATE `robots` SET `name` = "Astro boy" WHERE id = 101

public function useExplicitIdValue(): bool;
检查数据库系统是否需要为标识列提供显式值

public function viewExists( string $viewName, string $schemaName = null ): bool;
生成检查模式.视图是否存在的SQL

var_dump(
    $connection->viewExists("active_users", "posts")
);

Db\Adapter\AdapterInterfaceInterface

GitHub上的源码

  • 命名空间

    • Phalcon\Db\Adapter
  • 使用

    • Phalcon\Db\ColumnInterface
    • Phalcon\Db\DialectInterface
    • Phalcon\Db\IndexInterface
    • Phalcon\Db\RawValue
    • Phalcon\Db\ReferenceInterface
    • Phalcon\Db\ResultInterface
  • 继承

  • 实现

Phalcon\Db 适配器的接口

方法

public function addColumn( string $tableName, string $schemaName, ColumnInterface $column ): bool;
向表中添加一列

public function addForeignKey( string $tableName, string $schemaName, ReferenceInterface $reference ): bool;
向表中添加外键

public function addIndex( string $tableName, string $schemaName, IndexInterface $index ): bool;
向表中添加索引

public function addPrimaryKey( string $tableName, string $schemaName, IndexInterface $index ): bool;
向表中添加主键

public function affectedRows(): int;
返回数据库系统报告的上一次 INSERT/UPDATE/DELETE 影响的行数

public function begin( bool $nesting = bool ): bool;
在连接中启动一个事务

public function close(): void;
关闭活动连接并返回成功状态。Phalcon 在 Phalcon\Db\Pool 中自动关闭并销毁活动连接

public function commit( bool $nesting = bool ): bool;
提交连接中的活动事务

public function connect( array $descriptor = [] ): void;
此方法在 \Phalcon\Db\Adapter\Pdo 构造函数中自动调用。当需要恢复数据库连接时请调用它

public function createSavepoint( string $name ): bool;
创建一个新的保存点

public function createTable( string $tableName, string $schemaName, array $definition ): bool;
创建一个表

public function createView( string $viewName, array $definition, string $schemaName = null ): bool;
创建视图

public function delete( mixed $table, string $whereCondition = null, array $placeholders = [], array $dataTypes = [] ): bool;
使用自定义 RDBMS SQL 语法从表中删除数据

public function describeColumns( string $table, string $schema = null ): ColumnInterface[];
返回描述表的 Phalcon\Db\Column 对象数组

public function describeIndexes( string $table, string $schema = null ): IndexInterface[];
列出表的索引

public function describeReferences( string $table, string $schema = null ): ReferenceInterface[];
列出表的引用

public function dropColumn( string $tableName, string $schemaName, string $columnName ): bool;
从表中删除一列

public function dropForeignKey( string $tableName, string $schemaName, string $referenceName ): bool;
从表中删除外键

public function dropIndex( string $tableName, string $schemaName, string $indexName ): bool;
从表中删除索引

public function dropPrimaryKey( string $tableName, string $schemaName ): bool;
从表中删除主键

public function dropTable( string $tableName, string $schemaName = null, bool $ifExists = bool ): bool;
从模式/数据库中删除表

public function dropView( string $viewName, string $schemaName = null, bool $ifExists = bool ): bool;
删除视图

public function escapeIdentifier( mixed $identifier ): string;
转义列/表/模式名称

public function escapeString( string $str ): string;
转义一个值以避免 SQL 注入

public function execute( string $sqlStatement, array $bindParams = [], array $bindTypes = [] ): bool;
将 SQL 语句发送到数据库服务器并返回成功状态。仅当发送到服务器的 SQL 语句不返回任何行时使用此方法

public function fetchAll( string $sqlQuery, int $fetchMode = int, array $bindParams = [], array $bindTypes = [] ): array;
将查询结果全部转储为数组

public function fetchColumn( string $sqlQuery, array $placeholders = [], mixed $column = int ): string | bool;
返回 SQL 查询结果第一行的第 n 个字段

// Getting count of robots
$robotsCount = $connection->fetchColumn("SELECT COUNT(*) FROM robots");
print_r($robotsCount);

// Getting name of last edited robot
$robot = $connection->fetchColumn(
    "SELECT id, name FROM robots ORDER BY modified DESC",
    1
);
print_r($robot);

public function fetchOne( string $sqlQuery, int $fetchMode = int, array $bindParams = [], array $bindTypes = [] ): array;
返回 SQL 查询结果的第一行

public function forUpdate( string $sqlQuery ): string;
返回带有FOR UPDATE子句修改后的SQL

public function getColumnDefinition( ColumnInterface $column ): string;
返回列的SQL列定义

public function getColumnList( mixed $columnList ): string;
获取列列表

public function getConnectionId(): string;
获取活动连接的唯一标识符

public function getDefaultIdValue(): RawValue;
返回用于插入到标识列的默认标识值

public function getDefaultValue(): RawValue;
返回让RDBMS使用表定义中声明的默认值的默认值

// Inserting a new robot with a valid default value for the column 'year'
$success = $connection->insert(
    "robots",
    [
        "Astro Boy",
        $connection->getDefaultValue()
    ],
    [
        "name",
        "year",
    ]
);

@todo 如果适配器不支持,则返回 NULL

public function getDescriptor(): array;
返回用于连接到活动数据库的描述符

public function getDialect(): DialectInterface;
返回内部方言实例

public function getDialectType(): string;
返回所使用方言的名称

public function getInternalHandler(): mixed;
返回内部PDO处理器

public function getNestedTransactionSavepointName(): string;
返回嵌套事务要用的保存点名称

public function getRealSQLStatement(): string;
对象中的活动 SQL 语句,未替换绑定参数

public function getSQLBindTypes(): array;
对象中的当前SQL语句

public function getSQLStatement(): string;
对象中的当前SQL语句

public function getSQLVariables(): array;
对象中的当前SQL语句

public function getType(): string;
返回适配器所使用的数据库系统类型

public function insert( string $table, array $values, mixed $fields = null, mixed $dataTypes = null ): bool;
使用自定义 RDBMS SQL 语法向表插入数据

public function insertAsDict( string $table, mixed $data, mixed $dataTypes = null ): bool;
使用自定义 RBDM SQL 语法向表插入数据

// Inserting a new robot
$success = $connection->insertAsDict(
    "robots",
    [
        "name" => "Astro Boy",
        "year" => 1952,
    ]
);

// Next SQL sentence is sent to the database system
INSERT INTO `robots` (`name`, `year`) VALUES ("Astro boy", 1952);

public function isNestedTransactionsWithSavepoints(): bool;
返回是否嵌套事务应使用保存点

public function isUnderTransaction(): bool;
检查连接是否处于数据库事务中

public function lastInsertId( string $name = null ): string | bool;
返回最近SQL语句插入auto_increment列的插入ID

public function limit( string $sqlQuery, int $number ): string;
将LIMIT子句附加到sqlQuery参数上

public function listTables( string $schemaName = null ): array;
列出数据库中的所有表

public function listViews( string $schemaName = null ): array;
列出数据库中的所有视图

public function modifyColumn( string $tableName, string $schemaName, ColumnInterface $column, ColumnInterface $currentColumn = null ): bool;
基于定义修改表列

public function query( string $sqlStatement, array $bindParams = [], array $bindTypes = [] ): ResultInterface | bool;
向数据库服务器发送SQL语句并返回执行成功状态。当发送到服务器的SQL语句返回行时使用此方法

public function releaseSavepoint( string $name ): bool;
释放给定的保存点

public function rollback( bool $nesting = bool ): bool;
回滚连接中的活动事务

public function rollbackSavepoint( string $name ): bool;
回滚给定的保存点

public function setNestedTransactionsWithSavepoints( bool $nestedTransactionsWithSavepoints ): AdapterInterface;
设置是否嵌套事务应使用保存点

public function sharedLock( string $sqlQuery ): string;
返回带有LOCK IN SHARE MODE子句修改后的SQL

public function supportSequences(): bool;
检查数据库系统是否需要序列来生成自增数值

public function supportsDefaultValue(): bool;
SQLite不支持DEFAULT关键字

@废弃 将在下一个版本中移除

public function tableExists( string $tableName, string $schemaName = null ): bool;
生成检查模式.表是否存在的SQL

public function tableOptions( string $tableName, string $schemaName = null ): array;
获取表的创建选项

public function update( string $table, mixed $fields, mixed $values, mixed $whereCondition = null, mixed $dataTypes = null ): bool;
使用自定义 RDBMS SQL 语法更新表中的数据

public function updateAsDict( string $table, mixed $data, mixed $whereCondition = null, mixed $dataTypes = null ): bool;
使用自定义 RBDM SQL 语法更新表中的数据,另一种更方便的语法

// Updating existing robot
$success = $connection->updateAsDict(
    "robots",
    [
        "name" => "New Astro Boy",
    ],
    "id = 101"
);

// Next SQL sentence is sent to the database system
UPDATE `robots` SET `name` = "Astro boy" WHERE id = 101

public function useExplicitIdValue(): bool;
检查数据库系统是否需要为标识列提供显式值

public function viewExists( string $viewName, string $schemaName = null ): bool;
生成检查模式.视图是否存在的SQL

Db\Adapter\Pdo\AbstractPdoAbstract

GitHub上的源码

  • 命名空间

    • Phalcon\Db\Adapter\Pdo
  • 使用

    • Phalcon\Db\Adapter\AbstractAdapter
    • Phalcon\Db\Column
    • Phalcon\Db\Exception
    • Phalcon\Db\ResultInterface
    • Phalcon\Db\Result\PdoResult
    • Phalcon\Events\ManagerInterface
  • 继承

    AbstractAdapter

  • 实现

Phalcon\Db\Adapter\Pdo 是 Phalcon\Db 类,内部使用 PDO 连接到数据库

use Phalcon\Db\Adapter\Pdo\Mysql;

$config = [
    "host"     => "localhost",
    "dbname"   => "blog",
    "port"     => 3306,
    "username" => "sigma",
    "password" => "secret",
];

$connection = new Mysql($config);

属性

/**
 * Last affected rows
 *
 * @var int
 */
protected $affectedRows = ;

/**
 * PDO Handler
 *
 * @var \PDO
 */
protected $pdo;

方法

public function __construct( array $descriptor );
Phalcon\Db\Adapter\Pdo 的构造函数

public function affectedRows(): int;
返回数据库系统中最后执行的 INSERT/UPDATE/DELETE 影响的行数

$connection->execute(
    "DELETE FROM robots"
);

echo $connection->affectedRows(), " were deleted";

public function begin( bool $nesting = bool ): bool;
在连接中启动一个事务

public function close(): void;
关闭活动连接并返回成功状态。Phalcon 在请求结束时自动关闭并销毁活动连接

public function commit( bool $nesting = bool ): bool;
提交连接中的活动事务

public function connect( array $descriptor = [] ): void;
此方法在 \Phalcon\Db\Adapter\Pdo 构造函数中自动调用。

当需要恢复数据库连接时调用它。

use Phalcon\Db\Adapter\Pdo\Mysql;

// Make a connection
$connection = new Mysql(
    [
        "host"     => "localhost",
        "username" => "sigma",
        "password" => "secret",
        "dbname"   => "blog",
        "port"     => 3306,
    ]
);

// Reconnect
$connection->connect();

public function convertBoundParams( string $sql, array $params = [] ): array;
将像 :name: 或 ?1 这样的绑定参数转换为 PDO 绑定参数 ?

print_r(
    $connection->convertBoundParams(
        "SELECTFROM robots WHERE name = :name:",
        [
            "Bender",
        ]
    )
);

public function escapeString( string $str ): string;
根据连接中的当前字符集转义值,以避免 SQL 注入

$escapedStr = $connection->escapeString("some dangerous value");

public function execute( string $sqlStatement, array $bindParams = [], array $bindTypes = [] ): bool;
将 SQL 语句发送到数据库服务器并返回成功状态。仅当发送到服务器的 SQL 语句不返回任何行时使用此方法

// Inserting data
$success = $connection->execute(
    "INSERT INTO robots VALUES (1, 'Astro Boy')"
);

$success = $connection->execute(
    "INSERT INTO robots VALUES (?, ?)",
    [
        1,
        "Astro Boy",
    ]
);

public function executePrepared( \PDOStatement $statement, array $placeholders, mixed $dataTypes ): \PDOStatement;
执行带有绑定的预处理语句。此函数使用从零开始的整数索引

use Phalcon\Db\Column;

$statement = $db->prepare(
    "SELECTFROM robots WHERE name = :name"
);

$result = $connection->executePrepared(
    $statement,
    [
        "name" => "Voltron",
    ],
    [
        "name" => Column::BIND_PARAM_STR,
    ]
);

public function getErrorInfo(): array;
返回错误信息(如果有)

public function getInternalHandler(): mixed;
返回内部PDO处理器

public function getTransactionLevel(): int;
返回当前事务嵌套级别

public function isUnderTransaction(): bool;
检查连接是否处于事务中

$connection->begin();

// true
var_dump(
    $connection->isUnderTransaction()
);

public function lastInsertId( string $name = null ): string | bool;
返回最近执行的 SQL 语句中插入的 auto_increment/serial 列的插入 ID

// Inserting a new robot
$success = $connection->insert(
    "robots",
    [
        "Astro Boy",
        1952,
    ],
    [
        "name",
        "year",
    ]
);

// Getting the generated id
$id = $connection->lastInsertId();

public function prepare( string $sqlStatement ): \PDOStatement;
返回准备好执行 'executePrepared' 的 PDO 预处理语句

use Phalcon\Db\Column;

$statement = $db->prepare(
    "SELECTFROM robots WHERE name = :name"
);

$result = $connection->executePrepared(
    $statement,
    [
        "name" => "Voltron",
    ],
    [
        "name" => Column::BIND_PARAM_INT,
    ]
);

public function query( string $sqlStatement, array $bindParams = [], array $bindTypes = [] ): ResultInterface | bool;
将 SQL 语句发送到数据库服务器并返回成功状态。仅当发送到服务器的 SQL 语句返回行时使用此方法

// Querying data
$resultset = $connection->query(
    "SELECTFROM robots WHERE type = 'mechanical'"
);

$resultset = $connection->query(
    "SELECTFROM robots WHERE type = ?",
    [
        "mechanical",
    ]
);

public function rollback( bool $nesting = bool ): bool;
回滚连接中的活动事务

abstract protected function getDsnDefaults(): array;
以键值对的形式返回PDO适配器的DSN默认值

protected function prepareRealSql( string $statement, array $parameters ): void;
构造SQL语句(包含参数)

@参见 https://stackoverflow.com/a/8403150

Db\Adapter\Pdo\Mysql

GitHub上的源码

  • 命名空间

    • Phalcon\Db\Adapter\Pdo
  • 使用

    • Phalcon\Db\Adapter\Pdo\AbstractPdo
    • Phalcon\Db\Column
    • Phalcon\Db\ColumnInterface
    • Phalcon\Db\Enum
    • Phalcon\Db\Exception
    • Phalcon\Db\Index
    • Phalcon\Db\IndexInterface
    • Phalcon\Db\Reference
    • Phalcon\Db\ReferenceInterface
  • 继承

    PdoAdapter

  • 实现

MySQL数据库系统的特定函数

use Phalcon\Db\Adapter\Pdo\Mysql;

$config = [
    "host"     => "localhost",
    "dbname"   => "blog",
    "port"     => 3306,
    "username" => "sigma",
    "password" => "secret",
];

$connection = new Mysql($config);

属性

/**
 * @var string
 */
protected $dialectType = mysql;

/**
 * @var string
 */
protected $type = mysql;

方法

public function addForeignKey( string $tableName, string $schemaName, ReferenceInterface $reference ): bool;
向表中添加外键

public function describeColumns( string $table, string $schema = null ): ColumnInterface[];
返回描述表的 Phalcon\Db\Column 对象数组

print_r(
    $connection->describeColumns("posts")
);

public function describeIndexes( string $table, string $schema = null ): IndexInterface[];
列出表的索引

print_r(
    $connection->describeIndexes("robots_parts")
);

public function describeReferences( string $table, string $schema = null ): ReferenceInterface[];
列出表的引用

print_r(
    $connection->describeReferences("robots_parts")
);

protected function getDsnDefaults(): array;
以键值对的形式返回PDO适配器的DSN默认值

Db\Adapter\Pdo\Postgresql

GitHub上的源码

  • 命名空间

    • Phalcon\Db\Adapter\Pdo
  • 使用

    • Phalcon\Db\Adapter\Pdo\AbstractPdo
    • Phalcon\Db\Column
    • Phalcon\Db\ColumnInterface
    • Phalcon\Db\Enum
    • Phalcon\Db\Exception
    • Phalcon\Db\RawValue
    • Phalcon\Db\Reference
    • Phalcon\Db\ReferenceInterface
    • Throwable
  • 继承

    PdoAdapter

  • 实现

PostgreSQL数据库系统的特定函数

use Phalcon\Db\Adapter\Pdo\Postgresql;

$config = [
    "host"     => "localhost",
    "dbname"   => "blog",
    "port"     => 5432,
    "username" => "postgres",
    "password" => "secret",
];

$connection = new Postgresql($config);

属性

/**
 * @var string
 */
protected $dialectType = postgresql;

/**
 * @var string
 */
protected $type = pgsql;

方法

public function __construct( array $descriptor );
Phalcon\Db\Adapter\Pdo\Postgresql的构造函数

public function connect( array $descriptor = [] ): void;
此方法在Phalcon\Db\Adapter\Pdo构造函数中自动调用。当需要恢复数据库连接时请调用它

public function createTable( string $tableName, string $schemaName, array $definition ): bool;
创建一个表

public function describeColumns( string $table, string $schema = null ): ColumnInterface[];
返回描述表的 Phalcon\Db\Column 对象数组

print_r(
    $connection->describeColumns("posts")
);

public function describeReferences( string $table, string $schema = null ): ReferenceInterface[];
列出表的引用

print_r(
    $connection->describeReferences("robots_parts")
);

public function getDefaultIdValue(): RawValue;
返回用于插入到标识列中的默认标识值

// Inserting a new robot with a valid default value for the column 'id'
$success = $connection->insert(
    "robots",
    [
        $connection->getDefaultIdValue(),
        "Astro Boy",
        1952,
    ],
    [
        "id",
        "name",
        "year",
    ]
);

public function modifyColumn( string $tableName, string $schemaName, ColumnInterface $column, ColumnInterface $currentColumn = null ): bool;
基于定义修改表列

public function supportSequences(): bool;
检查数据库系统是否需要序列来生成自增数值

public function useExplicitIdValue(): bool;
检查数据库系统是否需要为标识列提供显式值

protected function getDsnDefaults(): array;
以键值对的形式返回PDO适配器的DSN默认值

Db\Adapter\Pdo\Sqlite

GitHub上的源码

  • 命名空间

    • Phalcon\Db\Adapter\Pdo
  • 使用

    • Phalcon\Db\Adapter\Pdo\AbstractPdo
    • Phalcon\Db\Column
    • Phalcon\Db\ColumnInterface
    • Phalcon\Db\Enum
    • Phalcon\Db\Exception
    • Phalcon\Db\Index
    • Phalcon\Db\IndexInterface
    • Phalcon\Db\RawValue
    • Phalcon\Db\Reference
    • Phalcon\Db\ReferenceInterface
  • 继承

    PdoAdapter

  • 实现

SQLite数据库系统的特定函数

use Phalcon\Db\Adapter\Pdo\Sqlite;

$connection = new Sqlite(
    [
        "dbname" => "/tmp/test.sqlite",
    ]
);

属性

/**
 * @var string
 */
protected $dialectType = sqlite;

/**
 * @var string
 */
protected $type = sqlite;

方法

public function __construct( array $descriptor );
Phalcon\Db\Adapter\Pdo\Sqlite的构造函数

public function connect( array $descriptor = [] ): void;
此方法在Phalcon\Db\Adapter\Pdo构造函数中自动调用。当需要恢复数据库连接时请调用它

public function describeColumns( string $table, string $schema = null ): ColumnInterface[];
返回描述表的 Phalcon\Db\Column 对象数组

print_r(
    $connection->describeColumns("posts")
);

public function describeIndexes( string $table, string $schema = null ): IndexInterface[];
列出表的索引

print_r(
    $connection->describeIndexes("robots_parts")
);

public function describeReferences( string $table, string $schema = null ): ReferenceInterface[];
列出表的引用

public function getDefaultValue(): RawValue;
返回让RDBMS使用表定义中声明的默认值的默认值

// Inserting a new robot with a valid default value for the column 'year'
$success = $connection->insert(
    "robots",
    [
        "Astro Boy",
        $connection->getDefaultValue(),
    ],
    [
        "name",
        "year",
    ]
);

public function supportsDefaultValue(): bool;
SQLite不支持DEFAULT关键字

@废弃 将在下一个版本中移除

public function useExplicitIdValue(): bool;
检查数据库系统是否需要为标识列提供显式值

protected function getDsnDefaults(): array;
以键值对的形式返回PDO适配器的DSN默认值

Db\Adapter\PdoFactory

GitHub上的源码

  • 命名空间

    • Phalcon\Db\Adapter
  • 使用

    • Phalcon\Factory\AbstractFactory
    • Phalcon\Support\Helper\Arr\Get
  • 继承

    AbstractFactory

  • 实现

该文件是Phalcon框架的一部分。

(c) Phalcon团队team@phalcon.io

有关完整的版权和许可信息,请查看随此源代码分发的LICENSE.txt文件。

方法

public function __construct( array $services = [] );
构造函数

public function load( mixed $config ): AdapterInterface;
从Config对象创建实例的工厂

public function newInstance( string $name, array $options = [] ): AdapterInterface;
创建适配器的新实例

protected function getExceptionClass(): string;

protected function getServices(): array;
返回可用的适配器

Db\Column

GitHub上的源码

  • 命名空间

    • Phalcon\Db
  • 使用

  • 继承

  • 实现

    • ColumnInterface

允许定义在创建或修改表操作中使用的列

use Phalcon\Db\Column as Column;

// Column definition
$column = new Column(
    "id",
    [
        "type"          => Column::TYPE_INTEGER,
        "size"          => 10,
        "unsigned"      => true,
        "notNull"       => true,
        "autoIncrement" => true,
        "first"         => true,
        "comment"       => "",
    ]
);

// Add column to existing table
$connection->addColumn("robots", null, $column);

常量

const BIND_PARAM_BLOB = 3;
const BIND_PARAM_BOOL = 5;
const BIND_PARAM_DECIMAL = 32;
const BIND_PARAM_INT = 1;
const BIND_PARAM_NULL = 0;
const BIND_PARAM_STR = 2;
const BIND_SKIP = 1024;
const TYPE_BIGINTEGER = 14;
const TYPE_BINARY = 27;
const TYPE_BIT = 19;
const TYPE_BLOB = 11;
const TYPE_BOOLEAN = 8;
const TYPE_CHAR = 5;
const TYPE_DATE = 1;
const TYPE_DATETIME = 4;
const TYPE_DECIMAL = 3;
const TYPE_DOUBLE = 9;
const TYPE_ENUM = 18;
const TYPE_FLOAT = 7;
const TYPE_INTEGER = 0;
const TYPE_JSON = 15;
const TYPE_JSONB = 16;
const TYPE_LONGBLOB = 13;
const TYPE_LONGTEXT = 24;
const TYPE_MEDIUMBLOB = 12;
const TYPE_MEDIUMINTEGER = 21;
const TYPE_MEDIUMTEXT = 23;
const TYPE_SMALLINTEGER = 22;
const TYPE_TEXT = 6;
const TYPE_TIME = 20;
const TYPE_TIMESTAMP = 17;
const TYPE_TINYBLOB = 10;
const TYPE_TINYINTEGER = 26;
const TYPE_TINYTEXT = 25;
const TYPE_VARBINARY = 28;
const TYPE_VARCHAR = 2;

属性

/**
 * Column Position
 *
 * @var string|null
 */
protected $after;

/**
 * Column is autoIncrement?
 *
 * @var bool
 */
protected $autoIncrement = false;

/**
 * Bind Type
 *
 * @var int
 */
protected $bindType = 2;

/**
 * Column's comment
 *
 * @var string|null
 */
protected $comment;

/**
 * Default column value
 *
 * @var mixed|null
 */
protected $defaultValue;

/**
 * Position is first
 *
 * @var bool
 */
protected $first = false;

/**
 * The column have some numeric type?
 *
 * @var bool
 */
protected $isNumeric = false;

/**
 * Column's name
 *
 * @var string
 */
protected $name;

/**
 * Column not nullable?
 *
 * Default SQL definition is NOT NULL.
 *
 * @var bool
 */
protected $notNull = true;

/**
 * Column is part of the primary key?
 *
 * @var bool
 */
protected $primary = false;

/**
 * Integer column number scale
 *
 * @var int
 */
protected $scale = ;

/**
 * Integer column size
 *
 * @var int|string
 */
protected $size = ;

/**
 * Column data type
 *
 * @var int
 */
protected $type;

/**
 * Column data type reference
 *
 * @var int
 */
protected $typeReference = -1;

/**
 * Column data type values
 *
 * @var array|string
 */
protected $typeValues;

/**
 * Integer column unsigned?
 *
 * @var bool
 */
protected $unsigned = false;

方法

public function __construct( string $name, array $definition );
Phalcon\Db\Column的构造函数

public function getAfterPosition(): string | null;
检查字段是否绝对位于表的位置

public function getBindType(): int;
返回绑定处理的类型

public function getComment(): string | null;
列的注释

public function getDefault(): mixed;
列的默认值

public function getName(): string;
列的名称

public function getScale(): int;
整数列的小数位数

public function getSize(): int | string;
整数列的大小

public function getType(): int;
列的数据类型

public function getTypeReference(): int;
列的数据类型引用

public function getTypeValues(): array | string;
列的数据类型值

public function hasDefault(): bool;
检查列是否有默认值

public function isAutoIncrement(): bool;
自增

public function isFirst(): bool;
检查列是否位于表的第一个位置

public function isNotNull(): bool;
非空

public function isNumeric(): bool;
检查列是否为数字类型

public function isPrimary(): bool;
列是主键的一部分吗?

public function isUnsigned(): bool;
如果数值列是无符号的则返回true

Db\ColumnInterfaceInterface

GitHub上的源码

  • 命名空间

    • Phalcon\Db
  • 使用

  • 继承

  • 实现

Phalcon\Db\Column的接口

方法

public function getAfterPosition(): string | null;
检查字段是否绝对位于表的位置

public function getBindType(): int;
返回绑定处理的类型

public function getDefault(): mixed;
返回列的默认值

public function getName(): string;
返回列名

public function getScale(): int;
返回列的小数位数

public function getSize(): int | string;
返回列的大小

public function getType(): int;
返回列的类型

public function getTypeReference(): int;
返回列的类型引用

public function getTypeValues(): array | string;
返回列的类型值

public function hasDefault(): bool;
检查列是否有默认值

public function isAutoIncrement(): bool;
自增

public function isFirst(): bool;
检查列是否位于表的第一个位置

public function isNotNull(): bool;
非空

public function isNumeric(): bool;
检查列是否为数字类型

public function isPrimary(): bool;
列是主键的一部分吗?

public function isUnsigned(): bool;
如果数值列是无符号的则返回true

Db\DialectAbstract

GitHub上的源码

  • 命名空间

    • Phalcon\Db
  • 使用

  • 继承

  • 实现

    • DialectInterface

这是每个数据库方言的基类。它实现了将中间代码转换为其相关RDBMS语法的通用方法

属性

/**
 * @var string
 */
protected $escapeChar;

/**
 * @var array
 */
protected $customFunctions;

方法

public function createSavepoint( string $name ): string;
生成创建新保存点的SQL

final public function escape( string $str, string $escapeChar = null ): string;
转义标识符

final public function escapeSchema( string $str, string $escapeChar = null ): string;
转义模式

public function forUpdate( string $sqlQuery ): string;
返回带有FOR UPDATE子句修改后的SQL

$sql = $dialect->forUpdate("SELECTFROM robots");

echo $sql; // SELECTFROM robots FOR UPDATE

final public function getColumnList( array $columnList, string $escapeChar = null, array $bindCounts = [] ): string;
获取带有转义标识符的列列表

echo $dialect->getColumnList(
    [
        "column1",
        "column",
    ]
);

public function getCustomFunctions(): array;
返回已注册的函数

final public function getSqlColumn( mixed $column, string $escapeChar = null, array $bindCounts = [] ): string;
解析列表达式

public function getSqlExpression( array $expression, string $escapeChar = null, array $bindCounts = [] ): string;
将表达式的中间表示转换为数据库系统有效的表达式

final public function getSqlTable( mixed $table, string $escapeChar = null ): string;
将模式/表的中间表示转换为数据库系统有效的表达式

public function limit( string $sqlQuery, mixed $number ): string;
生成LIMIT子句的SQL

// SELECTFROM robots LIMIT 10
echo $dialect->limit(
    "SELECTFROM robots",
    10
);

// SELECTFROM robots LIMIT 10 OFFSET 50
echo $dialect->limit(
    "SELECTFROM robots",
    [10, 50]
);

public function registerCustomFunction( string $name, callable $customFunction ): Dialect;
注册自定义SQL函数

public function releaseSavepoint( string $name ): string;
生成释放保存点的SQL

public function rollbackSavepoint( string $name ): string;
生成回滚保存点的SQL

public function select( array $definition ): string;
构建SELECT语句

public function supportsReleaseSavepoints(): bool;
检查平台是否支持释放保存点

public function supportsSavepoints(): bool;
检查平台是否支持保存点

protected function checkColumnType( ColumnInterface $column ): string;
检查列类型,如果不是字符串则返回类型引用

protected function checkColumnTypeSql( ColumnInterface $column ): string;
检查列类型并返回更新后的SQL语句

protected function getColumnSize( ColumnInterface $column ): string;
返回括号中的列大小

protected function getColumnSizeAndScale( ColumnInterface $column ): string;
返回括号中的列大小和小数位数

final protected function getSqlExpressionAll( array $expression, string $escapeChar = null ): string;
解析

final protected function getSqlExpressionBinaryOperations( array $expression, string $escapeChar = null, array $bindCounts = [] ): string;
解析二元运算表达式

final protected function getSqlExpressionCase( array $expression, string $escapeChar = null, array $bindCounts = [] ): string;
解析CASE表达式

final protected function getSqlExpressionCastValue( array $expression, string $escapeChar = null, array $bindCounts = [] ): string;
解析值的CAST

final protected function getSqlExpressionConvertValue( array $expression, string $escapeChar = null, array $bindCounts = [] ): string;
解析值编码的CONVERT

final protected function getSqlExpressionFrom( mixed $expression, string $escapeChar = null ): string;
解析FROM子句

final protected function getSqlExpressionFunctionCall( array $expression, string $escapeChar = null, array $bindCounts = [] ): string;
解析函数调用

final protected function getSqlExpressionGroupBy( mixed $expression, string $escapeChar = null, array $bindCounts = [] ): string;
解析GROUP BY子句

final protected function getSqlExpressionHaving( array $expression, string $escapeChar = null, array $bindCounts = [] ): string;
解析HAVING子句

final protected function getSqlExpressionJoins( mixed $expression, string $escapeChar = null, array $bindCounts = [] ): string;
解析JOIN子句

final protected function getSqlExpressionLimit( mixed $expression, string $escapeChar = null, array $bindCounts = [] ): string;
解析LIMIT子句

final protected function getSqlExpressionList( array $expression, string $escapeChar = null, array $bindCounts = [] ): string;
解析列表

final protected function getSqlExpressionObject( array $expression, string $escapeChar = null, array $bindCounts = [] ): string;
解析对象表达式

final protected function getSqlExpressionOrderBy( mixed $expression, string $escapeChar = null, array $bindCounts = [] ): string;
解析ORDER BY子句

final protected function getSqlExpressionQualified( array $expression, string $escapeChar = null ): string;
解析限定表达式

final protected function getSqlExpressionScalar( array $expression, string $escapeChar = null, array $bindCounts = [] ): string;
解析列表达式

final protected function getSqlExpressionUnaryOperations( array $expression, string $escapeChar = null, array $bindCounts = [] ): string;
解析一元运算表达式

final protected function getSqlExpressionWhere( mixed $expression, string $escapeChar = null, array $bindCounts = [] ): string;
解析WHERE子句

protected function prepareColumnAlias( string $qualified, string $alias = null, string $escapeChar = null ): string;
准备此RDBMS的列

protected function prepareQualified( string $column, string $domain = null, string $escapeChar = null ): string;
准备此RDBMS的限定

protected function prepareTable( string $table, string $schema = null, string $alias = null, string $escapeChar = null ): string;
准备此RDBMS的表

Db\Dialect\Mysql

GitHub上的源码

  • 命名空间

    • Phalcon\Db\Dialect
  • 使用

    • Phalcon\Db\Column
    • Phalcon\Db\ColumnInterface
    • Phalcon\Db\Dialect
    • Phalcon\Db\DialectInterface
    • Phalcon\Db\Exception
    • Phalcon\Db\IndexInterface
    • Phalcon\Db\ReferenceInterface
  • 继承

    Dialect

  • 实现

为MySQL RDBMS生成特定数据库的SQL

属性

/**
 * @var string
 */
protected $escapeChar = `;

方法

public function addColumn( string $tableName, string $schemaName, ColumnInterface $column ): string;
生成用于向表中添加列的SQL

public function addForeignKey( string $tableName, string $schemaName, ReferenceInterface $reference ): string;
生成用于为表添加索引的SQL

public function addIndex( string $tableName, string $schemaName, IndexInterface $index ): string;
生成用于为表添加索引的SQL

public function addPrimaryKey( string $tableName, string $schemaName, IndexInterface $index ): string;
生成用于为表添加主键的SQL

public function createTable( string $tableName, string $schemaName, array $definition ): string;
生成用于创建表的SQL

public function createView( string $viewName, array $definition, string $schemaName = null ): string;
生成用于创建视图的SQL

public function describeColumns( string $table, string $schema = null ): string;
生成描述表的SQL

print_r(
    $dialect->describeColumns("posts")
);

public function describeIndexes( string $table, string $schema = null ): string;
生成用于查询表上的索引的SQL

public function describeReferences( string $table, string $schema = null ): string;
生成用于查询表上的外键的SQL

public function dropColumn( string $tableName, string $schemaName, string $columnName ): string;
生成用于从表中删除列的SQL

public function dropForeignKey( string $tableName, string $schemaName, string $referenceName ): string;
生成用于从表中删除外键的SQL

public function dropIndex( string $tableName, string $schemaName, string $indexName ): string;
生成用于从表中删除索引的SQL

public function dropPrimaryKey( string $tableName, string $schemaName ): string;
生成用于从表中删除主键的SQL

public function dropTable( string $tableName, string $schemaName = null, bool $ifExists = bool ): string;
生成用于删除表的SQL

public function dropView( string $viewName, string $schemaName = null, bool $ifExists = bool ): string;
生成用于删除视图的SQL

public function getColumnDefinition( ColumnInterface $column ): string;
获取MySQL中的列名

public function getForeignKeyChecks(): string;
生成SQL来检查DB参数FOREIGN_KEY_CHECKS

public function listTables( string $schemaName = null ): string;
列出数据库中的所有表

print_r(
    $dialect->listTables("blog")
);

public function listViews( string $schemaName = null ): string;
生成列出某个模式或用户的所有视图的SQL

public function modifyColumn( string $tableName, string $schemaName, ColumnInterface $column, ColumnInterface $currentColumn = null ): string;
生成用于修改表中列的SQL

public function sharedLock( string $sqlQuery ): string;
返回带有LOCK IN SHARE MODE子句修改后的SQL

$sql = $dialect->sharedLock("SELECTFROM robots");

echo $sql; // SELECTFROM robots LOCK IN SHARE MODE

public function tableExists( string $tableName, string $schemaName = null ): string;
生成检查模式.表是否存在的SQL

echo $dialect->tableExists("posts", "blog");

echo $dialect->tableExists("posts");

public function tableOptions( string $table, string $schema = null ): string;
生成描述表创建选项的SQL

public function truncateTable( string $tableName, string $schemaName ): string;
生成用于截断表的SQL

public function viewExists( string $viewName, string $schemaName = null ): string;
生成检查模式.视图是否存在的SQL

protected function getTableOptions( array $definition ): string;
生成添加表创建选项的SQL

Db\Dialect\Postgresql

GitHub上的源码

  • 命名空间

    • Phalcon\Db\Dialect
  • 使用

    • Phalcon\Db\Column
    • Phalcon\Db\ColumnInterface
    • Phalcon\Db\Dialect
    • Phalcon\Db\DialectInterface
    • Phalcon\Db\Exception
    • Phalcon\Db\IndexInterface
    • Phalcon\Db\ReferenceInterface
  • 继承

    Dialect

  • 实现

为PostgreSQL RDBMS生成特定数据库的SQL

属性

/**
 * @var string
 */
protected $escapeChar = \";

方法

public function addColumn( string $tableName, string $schemaName, ColumnInterface $column ): string;
生成用于向表中添加列的SQL

public function addForeignKey( string $tableName, string $schemaName, ReferenceInterface $reference ): string;
生成用于为表添加索引的SQL

public function addIndex( string $tableName, string $schemaName, IndexInterface $index ): string;
生成用于为表添加索引的SQL

public function addPrimaryKey( string $tableName, string $schemaName, IndexInterface $index ): string;
生成用于为表添加主键的SQL

public function createTable( string $tableName, string $schemaName, array $definition ): string;
生成用于创建表的SQL

public function createView( string $viewName, array $definition, string $schemaName = null ): string;
生成用于创建视图的SQL

public function describeColumns( string $table, string $schema = null ): string;
生成描述表的SQL

print_r(
    $dialect->describeColumns("posts")
);

public function describeIndexes( string $table, string $schema = null ): string;
生成用于查询表上的索引的SQL

public function describeReferences( string $table, string $schema = null ): string;
生成用于查询表上的外键的SQL

public function dropColumn( string $tableName, string $schemaName, string $columnName ): string;
生成用于从表中删除列的SQL

public function dropForeignKey( string $tableName, string $schemaName, string $referenceName ): string;
生成用于从表中删除外键的SQL

public function dropIndex( string $tableName, string $schemaName, string $indexName ): string;
生成用于从表中删除索引的SQL

public function dropPrimaryKey( string $tableName, string $schemaName ): string;
生成用于从表中删除主键的SQL

public function dropTable( string $tableName, string $schemaName = null, bool $ifExists = bool ): string;
生成用于删除表的SQL

public function dropView( string $viewName, string $schemaName = null, bool $ifExists = bool ): string;
生成用于删除视图的SQL

public function getColumnDefinition( ColumnInterface $column ): string;
获取PostgreSQL中的列名

public function listTables( string $schemaName = null ): string;
列出数据库中的所有表

print_r(
    $dialect->listTables("blog")
);

public function listViews( string $schemaName = null ): string;
生成列出某个模式或用户的所有视图的SQL

public function modifyColumn( string $tableName, string $schemaName, ColumnInterface $column, ColumnInterface $currentColumn = null ): string;
生成用于修改表中列的SQL

public function sharedLock( string $sqlQuery ): string;
返回一个带有共享锁语句修改的SQL。目前此方法返回原始查询

public function tableExists( string $tableName, string $schemaName = null ): string;
生成检查模式.表是否存在的SQL

echo $dialect->tableExists("posts", "blog");

echo $dialect->tableExists("posts");

public function tableOptions( string $table, string $schema = null ): string;
生成描述表创建选项的SQL

public function truncateTable( string $tableName, string $schemaName ): string;
生成用于截断表的SQL

public function viewExists( string $viewName, string $schemaName = null ): string;
生成检查模式.视图是否存在的SQL

protected function castDefault( ColumnInterface $column ): string;
protected function getTableOptions( array $definition ): string;

Db\Dialect\Postgresql

GitHub上的源码

  • 命名空间

    • Phalcon\Db\Dialect
  • 使用

    • Phalcon\Db\Column
    • Phalcon\Db\ColumnInterface
    • Phalcon\Db\Dialect
    • Phalcon\Db\DialectInterface
    • Phalcon\Db\Exception
    • Phalcon\Db\IndexInterface
    • Phalcon\Db\ReferenceInterface
  • 继承

    Dialect

  • 实现

为PostgreSQL RDBMS生成特定于数据库的SQL

属性

/**
 * @var string
 */
protected $escapeChar = \";

方法

public function addColumn( string $tableName, string $schemaName, ColumnInterface $column ): string;
生成用于向表中添加列的SQL

public function addForeignKey( string $tableName, string $schemaName, ReferenceInterface $reference ): string;
生成用于为表添加索引的SQL

public function addIndex( string $tableName, string $schemaName, IndexInterface $index ): string;
生成用于为表添加索引的SQL

public function addPrimaryKey( string $tableName, string $schemaName, IndexInterface $index ): string;
生成用于为表添加主键的SQL

public function createTable( string $tableName, string $schemaName, array $definition ): string;
生成用于创建表的SQL

public function createView( string $viewName, array $definition, string $schemaName = null ): string;
生成用于创建视图的SQL

public function describeColumns( string $table, string $schema = null ): string;
生成描述表的SQL

print_r(
    $dialect->describeColumns("posts")
);

public function describeIndex( string $index ): string;
生成用于查询表上索引详细信息的SQL

public function describeIndexes( string $table, string $schema = null ): string;
生成用于查询表上的索引的SQL

public function describeReferences( string $table, string $schema = null ): string;
生成用于查询表上的外键的SQL

public function dropColumn( string $tableName, string $schemaName, string $columnName ): string;
生成用于从表中删除列的SQL

public function dropForeignKey( string $tableName, string $schemaName, string $referenceName ): string;
生成用于从表中删除外键的SQL

public function dropIndex( string $tableName, string $schemaName, string $indexName ): string;
生成用于从表中删除索引的SQL

public function dropPrimaryKey( string $tableName, string $schemaName ): string;
生成用于从表中删除主键的SQL

public function dropTable( string $tableName, string $schemaName = null, bool $ifExists = bool ): string;
生成用于删除表的SQL

public function dropView( string $viewName, string $schemaName = null, bool $ifExists = bool ): string;
生成用于删除视图的SQL

public function forUpdate( string $sqlQuery ): string;
返回带有FOR UPDATE子句修改的SQL。对于SQLite,它返回原始查询

public function getColumnDefinition( ColumnInterface $column ): string;
获取SQLite中的列名

public function listIndexesSql( string $table, string $schema = null, string $keyName = null ): string;
生成获取索引查询列表的SQL

print_r(
    $dialect->listIndexesSql("blog")
);

public function listTables( string $schemaName = null ): string;
列出数据库中的所有表

print_r(
    $dialect->listTables("blog")
);

public function listViews( string $schemaName = null ): string;
生成列出某个模式或用户的所有视图的SQL

public function modifyColumn( string $tableName, string $schemaName, ColumnInterface $column, ColumnInterface $currentColumn = null ): string;
生成用于修改表中列的SQL

public function sharedLock( string $sqlQuery ): string;
返回一个带有共享锁语句修改的SQL。目前此方法返回原始查询

public function tableExists( string $tableName, string $schemaName = null ): string;
生成检查模式.表是否存在的SQL

echo $dialect->tableExists("posts", "blog");

echo $dialect->tableExists("posts");

public function tableOptions( string $table, string $schema = null ): string;
生成描述表创建选项的SQL

public function truncateTable( string $tableName, string $schemaName ): string;
生成用于截断表的SQL

public function viewExists( string $viewName, string $schemaName = null ): string;
生成检查模式.视图是否存在的SQL

Db\DialectInterfaceInterface

GitHub上的源码

  • 命名空间

    • Phalcon\Db
  • 使用

  • 继承

  • 实现

Phalcon\Db方言的接口

方法

public function addColumn( string $tableName, string $schemaName, ColumnInterface $column ): string;
生成用于向表中添加列的SQL

public function addForeignKey( string $tableName, string $schemaName, ReferenceInterface $reference ): string;
生成用于为表添加索引的SQL

public function addIndex( string $tableName, string $schemaName, IndexInterface $index ): string;
生成用于为表添加索引的SQL

public function addPrimaryKey( string $tableName, string $schemaName, IndexInterface $index ): string;
生成用于为表添加主键的SQL

public function createSavepoint( string $name ): string;
生成创建新保存点的SQL

public function createTable( string $tableName, string $schemaName, array $definition ): string;
生成用于创建表的SQL

public function createView( string $viewName, array $definition, string $schemaName = null ): string;
生成用于创建视图的SQL

public function describeColumns( string $table, string $schema = null ): string;
生成描述表的SQL

public function describeIndexes( string $table, string $schema = null ): string;
生成用于查询表上的索引的SQL

public function describeReferences( string $table, string $schema = null ): string;
生成用于查询表上的外键的SQL

public function dropColumn( string $tableName, string $schemaName, string $columnName ): string;
生成用于从表中删除列的SQL

public function dropForeignKey( string $tableName, string $schemaName, string $referenceName ): string;
生成用于从表中删除外键的SQL

public function dropIndex( string $tableName, string $schemaName, string $indexName ): string;
生成用于从表中删除索引的SQL

public function dropPrimaryKey( string $tableName, string $schemaName ): string;
生成用于从表中删除主键的SQL

public function dropTable( string $tableName, string $schemaName, bool $ifExists = bool ): string;
生成用于删除表的SQL

public function dropView( string $viewName, string $schemaName = null, bool $ifExists = bool ): string;
生成用于删除视图的SQL

public function forUpdate( string $sqlQuery ): string;
返回带有FOR UPDATE子句修改后的SQL

public function getColumnDefinition( ColumnInterface $column ): string;
获取RDBMS中的列名

public function getColumnList( array $columnList ): string;
获取列列表

public function getCustomFunctions(): array;
返回已注册的函数

public function getSqlExpression( array $expression, string $escapeChar = null, array $bindCounts = [] ): string;
将表达式的中间表示转换为数据库系统有效的表达式

public function limit( string $sqlQuery, mixed $number ): string;
生成LIMIT子句的SQL

public function listTables( string $schemaName = null ): string;
列出数据库中的所有表

public function modifyColumn( string $tableName, string $schemaName, ColumnInterface $column, ColumnInterface $currentColumn = null ): string;
生成用于修改表中列的SQL

public function registerCustomFunction( string $name, callable $customFunction ): Dialect;
注册自定义SQL函数

public function releaseSavepoint( string $name ): string;
生成释放保存点的SQL

public function rollbackSavepoint( string $name ): string;
生成回滚保存点的SQL

public function select( array $definition ): string;
构建SELECT语句

public function sharedLock( string $sqlQuery ): string;
返回带有LOCK IN SHARE MODE子句修改后的SQL

public function supportsReleaseSavepoints(): bool;
检查平台是否支持释放保存点

public function supportsSavepoints(): bool;
检查平台是否支持保存点

public function tableExists( string $tableName, string $schemaName = null ): string;
生成检查模式.表是否存在的SQL

public function tableOptions( string $table, string $schema = null ): string;
生成描述表创建选项的SQL

public function viewExists( string $viewName, string $schemaName = null ): string;
生成检查模式.视图是否存在的SQL

Db\Enum

GitHub上的源码

  • 命名空间

    • Phalcon\Db
  • 使用

  • 继承

  • 实现

Phalcon\Db的常量

常量

const FETCH_ASSOC;
const FETCH_BOTH;
const FETCH_BOUND;
const FETCH_CLASS;
const FETCH_CLASSTYPE;
const FETCH_COLUMN;
const FETCH_DEFAULT = 0;
const FETCH_FUNC;
const FETCH_GROUP;
const FETCH_INTO;
const FETCH_KEY_PAIR;
const FETCH_LAZY;
const FETCH_NAMED;
const FETCH_NUM;
const FETCH_OBJ;
const FETCH_ORI_NEXT;
const FETCH_PROPS_LATE;
const FETCH_SERIALIZE;
const FETCH_UNIQUE;

Db\Exception

GitHub上的源码

  • 命名空间

    • Phalcon\Db
  • 使用

  • 继承

    \Exception

  • 实现

Phalcon\Db抛出的异常将使用此类

Db\Index

GitHub上的源码

  • 命名空间

    • Phalcon\Db
  • 使用

  • 继承

  • 实现

    • IndexInterface

允许定义用于表的索引。索引是提高数据库性能的一种常见方式。索引允许数据库服务器比没有索引时更快地查找和检索特定行

// Define new unique index
$index_unique = new \Phalcon\Db\Index(
    'column_UNIQUE',
    [
        'column',
        'column',
    ],
    'UNIQUE'
);

// Define new primary index
$index_primary = new \Phalcon\Db\Index(
    'PRIMARY',
    [
        'column',
    ]
);

// Add index to existing table
$connection->addIndex("robots", null, $index_unique);
$connection->addIndex("robots", null, $index_primary);

属性

/**
 * Index columns
 *
 * @var array
 */
protected $columns;

/**
 * Index name
 *
 * @var string
 */
protected $name;

/**
 * Index type
 *
 * @var string
 */
protected $type;

方法

public function __construct( string $name, array $columns, string $type = string );
Phalcon\Db\Index构造函数

public function getColumns(): array;
索引列

public function getName(): string;
索引名称

public function getType(): string;
索引类型

Db\IndexInterfaceInterface

GitHub上的源码

  • 命名空间

    • Phalcon\Db
  • 使用

  • 继承

  • 实现

Phalcon\Db\Index的接口

方法

public function getColumns(): array;
获取对应索引的列

public function getName(): string;
获取索引名称

public function getType(): string;
获取索引类型

Db\Profiler

GitHub上的源码

  • 命名空间

    • Phalcon\Db
  • 使用

    • Phalcon\Db\Profiler\Item
  • 继承

  • 实现

Phalcon\Db的实例可以在发送到关系型数据库的SQL语句上生成执行分析。分析的信息包括以毫秒为单位的执行时间。这有助于您识别应用程序中的瓶颈。

use Phalcon\Db\Profiler;
use Phalcon\Events\Event;
use Phalcon\Events\Manager;

$profiler = new Profiler();
$eventsManager = new Manager();

$eventsManager->attach(
    "db",
    function (Event $event, $connection) use ($profiler) {
        if ($event->getType() === "beforeQuery") {
            $sql = $connection->getSQLStatement();

            // Start a profile with the active connection
            $profiler->startProfile($sql);
        }

        if ($event->getType() === "afterQuery") {
            // Stop the active profile
            $profiler->stopProfile();
        }
    }
);

// Set the event manager on the connection
$connection->setEventsManager($eventsManager);


$sql = "SELECT buyer_name, quantity, product_name
FROM buyers LEFT JOIN products ON
buyers.pid=products.id";

// Execute a SQL statement
$connection->query($sql);

// Get the last profile in the profiler
$profile = $profiler->getLastProfile();

echo "SQL Statement: ", $profile->getSQLStatement(), "\n";
echo "Start Time: ", $profile->getInitialTime(), "\n";
echo "Final Time: ", $profile->getFinalTime(), "\n";
echo "Total Elapsed Time: ", $profile->getTotalElapsedSeconds(), "\n";

属性

/**
 * Active Item
 *
 * @var Item
 */
protected $activeProfile;

/**
 * All the Items in the active profile
 *
 * @var Item[]
 */
protected $allProfiles;

/**
 * Total time spent by all profiles to complete in nanoseconds
 *
 * @var float
 */
protected $totalNanoseconds = ;

方法

public function getLastProfile(): Item;
返回在分析器中执行的最后一个分析

public function getNumberTotalStatements(): int;
返回已处理的SQL语句总数

public function getProfiles(): Item[];
返回所有已处理的分析记录

public function getTotalElapsedMilliseconds(): double;
返回分析所花费的总时间(毫秒)

public function getTotalElapsedNanoseconds(): double;
返回分析所花费的总时间(纳秒)

public function getTotalElapsedSeconds(): double;
返回分析所花费的总时间(秒)

public function reset(): Profiler;
重置分析器,清除所有分析记录

public function startProfile( string $sqlStatement, array $sqlVariables = [], array $sqlBindTypes = [] ): Profiler;
开始对一条SQL语句进行分析

public function stopProfile(): Profiler;
停止当前活动的分析

Db\Profiler\Item

GitHub上的源码

  • 命名空间

    • Phalcon\Db\Profiler
  • 使用

  • 继承

  • 实现

此类标识Phalcon\Db\Profiler中的每个分析记录

属性

/**
 * Timestamp when the profile ended
 *
 * @var double
 */
protected $finalTime;

/**
 * Timestamp when the profile started
 *
 * @var double
 */
protected $initialTime;

/**
 * SQL bind types related to the profile
 *
 * @var array
 */
protected $sqlBindTypes;

/**
 * SQL statement related to the profile
 *
 * @var string
 */
protected $sqlStatement;

/**
 * SQL variables related to the profile
 *
 * @var array
 */
protected $sqlVariables;

方法

public function getFinalTime(): double;
返回配置文件结束时的时间戳

public function getInitialTime(): double;
返回配置文件开始时的时间戳

public function getSqlBindTypes(): array;
返回与配置文件相关的SQL绑定类型

public function getSqlStatement(): string;
返回与配置文件相关的SQL语句

public function getSqlVariables(): array;
返回与配置文件相关的SQL变量

public function getTotalElapsedMilliseconds(): double;
返回配置文件所花费的总时间(以毫秒为单位)

public function getTotalElapsedNanoseconds(): double;
返回配置文件所花费的总时间(以纳秒为单位)

public function getTotalElapsedSeconds(): double;
返回配置文件所花费的总时间(以秒为单位)

public function setFinalTime( double $finalTime ): Item;
返回配置文件结束时的时间戳

public function setInitialTime( double $initialTime ): Item;
返回配置文件开始时的时间戳

public function setSqlBindTypes( array $sqlBindTypes ): Item;
返回与配置文件相关的SQL绑定类型

public function setSqlStatement( string $sqlStatement ): Item;
返回与配置文件相关的SQL语句

public function setSqlVariables( array $sqlVariables ): Item;
返回与配置文件相关的SQL变量

数据库\原始值

GitHub上的源码

  • 命名空间

    • Phalcon\Db
  • 使用

  • 继承

  • 实现

此类允许插入/更新原始数据而不进行引号或格式化。

下一个示例演示如何将MySQL的now()函数用作字段值。

$subscriber = new Subscribers();

$subscriber->email     = "andres@phalcon.io";
$subscriber->createdAt = new \Phalcon\Db\RawValue("now()");

$subscriber->save();

属性

/**
 * Raw value without quoting or formatting
 *
 * @var string
 */
protected $value;

方法

public function __construct( mixed $value );
Phalcon\Db\RawValue构造函数

public function __toString(): string;
public function getValue(): string;

数据库\外键约束

GitHub上的源码

  • 命名空间

    • Phalcon\Db
  • 使用

  • 继承

  • 实现

    • ReferenceInterface

允许在表上定义引用约束

$reference = new \Phalcon\Db\Reference(
    "field_fk",
    [
        "referencedSchema"  => "invoicing",
        "referencedTable"   => "products",
        "columns"           => [
            "producttype",
            "product_code",
        ],
        "referencedColumns" => [
            "type",
            "code",
        ],
    ]
);

属性

/**
 * Local reference columns
 *
 * @var array
 */
protected $columns;

/**
 * Constraint name
 *
 * @var string
 */
protected $name;

/**
 * Referenced Columns
 *
 * @var array
 */
protected $referencedColumns;

/**
 * Referenced Schema
 *
 * @var string
 */
protected $referencedSchema;

/**
 * Referenced Table
 *
 * @var string
 */
protected $referencedTable;

/**
 * Schema name
 *
 * @var string
 */
protected $schemaName;

/**
 * ON DELETE
 *
 * @var string
 */
protected $onDelete;

/**
 * ON UPDATE
 *
 * @var string
 */
protected $onUpdate;

方法

public function __construct( string $name, array $definition );
Phalcon\Db\Reference构造函数

public function getColumns(): array;
本地引用列

public function getName(): string;
约束名称

public function getOnDelete(): string;
ON DELETE

public function getOnUpdate(): string;
ON UPDATE

public function getReferencedColumns(): array;
被引用列

public function getReferencedSchema(): string;
被引用模式

public function getReferencedTable(): string;
被引用表

public function getSchemaName(): string;
模式名称

数据库\引用接口Interface

GitHub上的源码

  • 命名空间

    • Phalcon\Db
  • 使用

  • 继承

  • 实现

Phalcon\Db\Reference接口

方法

public function getColumns(): array;
获取引用所基于的本地列

public function getName(): string;
获取索引名称

public function getOnDelete(): string;
获取被引用的ON DELETE

public function getOnUpdate(): string;
获取被引用的ON UPDATE

public function getReferencedColumns(): array;
获取被引用列

public function getReferencedSchema(): string;
获取被引用表所在的模式

public function getReferencedTable(): string;
获取被引用表

public function getSchemaName(): string;
获取被引用表所在的模式

数据库\结果\PDO结果

GitHub上的源码

  • 命名空间

    • Phalcon\Db\Result
  • 使用

    • Phalcon\Db\Adapter\AdapterInterface
    • Phalcon\Db\Enum
    • Phalcon\Db\ResultInterface
  • 继承

  • 实现

    • ResultInterface

封装结果集内部

$result = $connection->query("SELECTFROM robots ORDER BY name");

$result->setFetchMode(
    \Phalcon\Db\Enum::FETCH_NUM
);

while ($robot = $result->fetchArray()) {
    print_r($robot);
}

属性

/**
 * @var array
 */
protected $bindParams;

/**
 * @var array
 */
protected $bindTypes;

/**
 * @var AdapterInterface
 */
protected $connection;

/**
 * Active fetch mode
 *
 * @var int
 */
protected $fetchMode;

/**
 * Internal resultset
 *
 * @var \PDOStatement
 */
protected $pdoStatement;

/**
 * @var mixed
 * TODO: Check if this property is used
 */
protected $result;

/**
 * @var bool
 */
protected $rowCount = false;

/**
 * @var string|null
 */
protected $sqlStatement;

方法

public function __construct( AdapterInterface $connection, \PDOStatement $result, mixed $sqlStatement = null, mixed $bindParams = null, mixed $bindTypes = null );
Phalcon\Db\Result\Pdo构造函数

public function dataSeek( int $number ): void;
将内部结果集游标移动到另一个位置,使我们能够获取某个行

$result = $connection->query(
    "SELECTFROM robots ORDER BY name"
);

// Move to third row on result
$result->dataSeek(2);

// Fetch third row
$row = $result->fetch();

public function execute(): bool;
允许再次执行语句。某些数据库系统不支持可滚动游标。因此由于游标只能向前移动,我们需要再次执行游标以从头开始获取行

public function fetch( int $fetchStyle = null, int $cursorOrientation = static-constant-access, int $cursorOffset = int );
获取对应于已获取行的字符串数组/对象,如果没有更多行,则返回FALSE。此方法受到使用设置的活动获取标志的影响Phalcon\Db\Result\Pdo::setFetchMode()

$result = $connection->query("SELECTFROM robots ORDER BY name");

$result->setFetchMode(
    \Phalcon\Enum::FETCH_OBJ
);

while ($robot = $result->fetch()) {
    echo $robot->name;
}

public function fetchAll( int $mode = static-constant-access, mixed $fetchArgument = static-constant-access, mixed $constructorArgs = null ): array;
返回包含结果中所有记录的数组的数组。此方法受到使用设置的活动获取标志的影响Phalcon\Db\Result\Pdo::setFetchMode()

$result = $connection->query(
    "SELECTFROM robots ORDER BY name"
);

$robots = $result->fetchAll();

public function fetchArray();
返回对应于已获取行的字符串数组,如果没有更多行,则返回FALSE。此方法受到使用设置的活动获取标志的影响Phalcon\Db\Result\Pdo::setFetchMode()

$result = $connection->query("SELECTFROM robots ORDER BY name");

$result->setFetchMode(
    \Phalcon\Enum::FETCH_NUM
);

while ($robot = result->fetchArray()) {
    print_r($robot);
}

public function getInternalResult(): \PDOStatement;
获取内部PDO结果对象

public function numRows(): int;
获取结果集返回的行数

$result = $connection->query(
    "SELECTFROM robots ORDER BY name"
);

echo "There are ", $result->numRows(), " rows in the resultset";

public function setFetchMode( int $fetchMode, mixed $colNoOrClassNameOrObject = null, mixed $ctorargs = null ): bool;
更改获取模式影响Phalcon\Db\Result\Pdo::fetch()

// Return array with integer indexes
$result->setFetchMode(
    \Phalcon\Enum::FETCH_NUM
);

// Return associative array without integer indexes
$result->setFetchMode(
    \Phalcon\Enum::FETCH_ASSOC
);

// Return associative array together with integer indexes
$result->setFetchMode(
    \Phalcon\Enum::FETCH_BOTH
);

// Return an object
$result->setFetchMode(
    \Phalcon\Enum::FETCH_OBJ
);

数据库\结果接口Interface

GitHub上的源码

  • 命名空间

    • Phalcon\Db
  • 使用

  • 继承

  • 实现

Phalcon\Db\Result对象的接口

方法

public function dataSeek( int $number );
将内部结果集游标移动到另一个位置,使我们能够获取某个行

public function execute(): bool;
允许再次执行语句。某些数据库系统不支持可滚动游标。因此由于游标只能向前移动,我们需要再次执行游标以从头开始获取行

public function fetch(): mixed;
获取对应于已获取行的字符串数组/对象,如果没有更多行,则返回FALSE。此方法受到使用设置的活动获取标志的影响Phalcon\Db\Result\Pdo::setFetchMode()

public function fetchAll(): array;
返回包含结果中的所有记录的数组的数组。此方法受到使用设置的活动获取标志的影响Phalcon\Db\Result\Pdo::setFetchMode()

public function fetchArray(): mixed;
返回对应于已获取行的字符串数组,如果没有更多行,则返回FALSE。此方法受到使用设置的活动获取标志的影响Phalcon\Db\Result\Pdo::setFetchMode()

public function getInternalResult(): \PDOStatement;
获取内部PDO结果对象

public function numRows(): int;
获取结果集返回的行数

public function setFetchMode( int $fetchMode ): bool;
更改获取模式影响Phalcon\Db\Result\Pdo::fetch()

无噪 Logo
无噪文档
25 年 6 月翻译
版本号 5.9
文档源↗