php8 pdo方式连接达梦数据库
下载php8 TS版本
下载地址:https://windows.php.net/download/
解压至:phpstudy目录下:phpstudy_pro\Extensions\php
将达梦安装目录下(D:\dmdbms\drivers\php_pdo)的 php80ts_dm.dll pdots_dm.dll dmdpi.dll 这三个文件复制到php的ext目录下(D:\BC\phpstudy_pro\Extensions\php\php8.0.25ts\ext)
php.ini中 增加
5、到这里。dm 以及 pdo配置完成
tp6配置:
6.1 config/database文件中
6.2 vendor/topthink/think-orm/src/db/builder下创建Dm.php文件(根据网上的方法已修改为适用于tp6)
declare (strict_types = 1);// +----------------------------------------------------------------------// | ThinkPHP [ WE CAN DO IT JUST THINK ]// +----------------------------------------------------------------------// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )// +----------------------------------------------------------------------// | Author: liu21st // +----------------------------------------------------------------------namespace think\db\builder;use think\db\Builder;use think\db\Query;class Dm extends Builder{ protected $selectSql = 'SELECT * FROM (SELECT thinkphp.*, rownum AS numrow FROM (SELECT %DISTINCT% %FIELD% FROM %TABLE%%JOIN%%WHERE%%GROUP%%HAVING%%ORDER%) thinkphp ) %LIMIT%%COMMENT%'; protected function parseLimit(Query $query, string $limit): string { $limitStr = ''; if (!empty($limit)) { $limit = explode(',', $limit); if (count($limit) > 1) { $limitStr = "(numrow>" . $limit[0] . ") AND (numrow<=" . ($limit[0] + $limit[1]) . ")"; } else { $limitStr = "(numrow>0 AND numrow<=" . $limit[0] . ")"; } } return $limitStr ? ' WHERE ' . $limitStr : ''; } protected function parseLock(Query $query, $lock = false): string { if (!$lock) { return ''; } return ' FOR UPDATE NOWAIT '; } public function parseKey(Query $query, $key, bool $strict = false): string { $key = trim($key); if (strpos($key, '->') && false === strpos($key, '(')) { // JSON字段支持 list($field, $name) = explode($key, '->'); $key = $field . '."' . $name . '"'; } return $key; } protected function parseRand(Query $query): string { return 'DBMS_RANDOM.value'; }}
3 vendor/topthink/think-orm/src/db/connector下创建Dm.php(适用于tp6)
// +----------------------------------------------------------------------// | ThinkPHP [ WE CAN DO IT JUST THINK ]// +----------------------------------------------------------------------// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )// +----------------------------------------------------------------------// | Author: liu21st // +----------------------------------------------------------------------namespace think\db\connector;use PDO;use think\db\BaseQuery;use think\db\Connection;use think\db\PDOConnection;use think\db\ConnectionInterface;// class Dm extends Connectionclass Dm extends PDOConnection{ protected function parseDsn(array $config): string { // $dsn = 'dm:host='; // if (!empty($config['hostname'])) { // // dm Instant Client // $dsn .= $config['hostname'] . ($config['hostport'] ? ':' . $config['hostport'] : '') . '/'; // // $dsn .= $config['hostname']; // } // if (!empty($config['charset'])) { // $dsn .= ';charset=' . $config['charset']; // } // return $dsn; $dsn = "dm:host=".$config['hostname']; return $dsn; } public function getFields(string $tableName): array { list($tableName) = explode(' ', $tableName); $sql = "select a.column_name,data_type,DECODE (nullable, 'Y', 0, 1) notnull,data_default, DECODE (A .column_name,b.column_name,1,0) pk from all_tab_columns a,(select column_name from all_constraints c, all_cons_columns col where c.constraint_name = col.constraint_name and c.constraint_type = 'P' and c.table_name = '" . strtoupper($tableName) . "' ) b where table_name = '" . strtoupper($tableName) . "' and a.column_name = b.column_name (+)"; // $pdo = $this->query($sql, [], false, true); // $result = $pdo->fetchAll(PDO::FETCH_ASSOC); $pdo = $this->getPDOStatement($sql); $result = $pdo->fetchAll(PDO::FETCH_ASSOC); $info = []; if ($result) { foreach ($result as $key => $val) { $val = array_change_key_case($val); $info[$val['column_name']] = [ 'name' => $val['column_name'], 'type' => $val['data_type'], 'notnull' => $val['notnull'], 'default' => $val['data_default'], 'primary' => $val['pk'], 'autoinc' => $val['pk'], ]; } } return $this->fieldCase($info); } public function getTables(string $dbName = ''): array { $sql = 'select table_name from all_tables'; // $pdo = $this->query($sql, [], false, true); // $result = $pdo->fetchAll(PDO::FETCH_ASSOC); $pdo = $this->getPDOStatement($sql); $result = $pdo->fetchAll(PDO::FETCH_ASSOC); $info = []; foreach ($result as $key => $val) { $info[$key] = current($val); } return $info; } // public function getLastInsID($sequence = null) public function getLastInsID(BaseQuery $query, string $sequence = null) { $pdo = $this->linkID->query("select {$sequence}.currval as id from dual"); $insertId = $pdo->fetchColumn(); return $this->autoInsIDType($query, $insertId); } protected function getExplain(string $sql) { return []; } protected function supportSavepoint(): bool { return true; }}
至此,配置完毕
增删改查一如既往,只是关于数据库中的字段都要大写了
来源地址:https://blog.csdn.net/qq_22471701/article/details/127785640