FLEAPHP框架下Mysqli连接扩展
公司老的CRM系统是基于FLEAPHP,这玩意老早就不更新了,当php升级到5.5后,系统会提示mysql_connect函数即将被废弃,建议跟换mysqli或pdo,nnd逼我换框架么,好吧我只是随便说说,还是自己动手,丰衣足食。 新增一个Mysqli.php,修改Abstract.php文件。 使用方
公司老的CRM系统是基于FLEAPHP,这玩意老早就不更新了,当php升级到5.5后,系统会提示mysql_connect函数即将被废弃,建议跟换mysqli或pdo,nnd逼我换框架么,好吧我只是随便说说,还是自己动手,丰衣足食。
新增一个 Mysqli.php,修改Abstract.php 文件。
使用方法:
将两个文件放到"FLEA\Db\Driver\"目录下,覆盖即可。
Ps:Abstract.php只是做了一个很小的兼容性修改,不影响其他功能。 FleaPHP
<?php /** * 定义 FLEA_Db_Driver_Mysqli 驱动 基于FLEA_Db_Driver_Mysql 修改 * by 豚鼠窝窝 2014.05.07 * maophp@qq.com */ // {{{ includes FLEA::loadClass('FLEA_Db_Driver_Abstract'); // }}} class FLEA_Db_Driver_Mysqli extends FLEA_Db_Driver_Abstract { var $NEXT_ID_SQL = 'UPDATE %s SET id = LAST_INSERT_ID(id + 1)'; var $CREATE_SEQ_SQL = 'CREATE TABLE %s (id INT NOT NULL)'; var $INIT_SEQ_SQL = 'INSERT INTO %s VALUES (%s)'; var $DROP_SEQ_SQL = 'DROP TABLE %s'; var $META_COLUMNS_SQL = 'SHOW FULL COLUMNS FROM %s'; var $PARAM_STYLE = DBO_PARAM_QM; var $HAS_INSERT_ID = true; var $HAS_AFFECTED_ROWS = true; var $_mysqlVersion = null; function connect($dsn = false) { $this->lasterr = null; $this->lasterrcode = null; if ($this->conn && $dsn == false) { return true; } if (!$dsn) { $dsn = $this->dsn; } else { $this->dsn = $dsn; } if (isset($dsn['port']) && $dsn['port'] != '') { $host = $dsn['host'] . ':' . $dsn['port']; } else { $host = $dsn['host']; } if (!isset($dsn['login'])) { $dsn['login'] = ''; } if (!isset($dsn['password'])) { $dsn['password'] = ''; } if (!empty($dsn['options'])) { $this->conn = mysqli_connect($host, $dsn['login'], $dsn['password'], false, $dsn['options']); } else { $this->conn = mysqli_connect($host, $dsn['login'], $dsn['password']); } if (!$this->conn) { FLEA::loadClass('FLEA_Db_Exception_SqlQuery'); return __THROW(new FLEA_Db_Exception_SqlQuery("mysqli_connect('{$host}', '{$dsn['login']}') failed!", mysqli_error(), mysqli_errno())); } if (!empty($dsn['database'])) { if (!$this->selectDb($dsn['database'])) { return false; } } $this->_mysqlVersion = $this->getOne('SELECT VERSION()'); if (isset($dsn['charset']) && $dsn['charset'] != '') { $charset = $dsn['charset']; } else { $charset = FLEA::getAppInf('databaseCharset'); } if ($this->_mysqlVersion >= '4.1' && $charset != '') { if (!$this->execute("SET NAMES '" . $charset . "'")) { return false; } } if ($this->_mysqlVersion >= '5.0') { $this->HAS_SAVEPOINT = true; } return true; } function close() { if ($this->conn) { mysqli_close($this->conn); } parent::close(); } function selectDb($database) { if (!mysqli_select_db( $this->conn, $database)) { FLEA::loadClass('FLEA_Db_Exception_SqlQuery'); return __THROW(new FLEA_Db_Exception_SqlQuery("SELECT DATABASE: '{$database}' FAILED!", mysqli_error($this->conn), mysqli_errno($this->conn))); } return true; } function execute($sql, $inputarr = null, $throw = true) { if (is_array($inputarr)) { $sql = $this->bind($sql, $inputarr); } if ($this->enableLog) { $this->log[] = $sql; log_message("sql: {$sql}", 'debug'); } $this->querycount++; $result = mysqli_query($this->conn, $sql,MYSQLI_USE_RESULT); if ($result !== false) { $this->lasterr = null; $this->lasterrcode = null; return $result; } $this->lasterr = mysqli_error($this->conn); $this->lasterrcode = mysqli_errno($this->conn); if ($throw) { FLEA::loadClass('FLEA_Db_Exception_SqlQuery'); __THROW(new FLEA_Db_Exception_SqlQuery($sql, $this->lasterr, $this->lasterrcode)); } return false; } function qstr($value) { if (is_int($value) || is_float($value)) { return $value; } if (is_bool($value)) { return $value ? $this->TRUE_VALUE : $this->FALSE_VALUE; } if (is_null($value)) { return $this->NULL_VALUE; } return "'" . mysqli_real_escape_string($this->conn, $value) . "'"; } function qtable($tableName, $schema = null) { return $schema != '' ? "`{$schema}`.`{$tableName}`" : "`{$tableName}`"; } function qfield($fieldName, $tableName = null, $schema = null) { $fieldName = ($fieldName == '*') ? '*' : "`{$fieldName}`"; return $tableName != '' ? $this->qtable($tableName, $schema) . '.' . $fieldName : $fieldName; } function _insertId() { return mysqli_insert_id($this->conn); } function _affectedRows() { return mysqli_affected_rows($this->conn); } function fetchRow($res) { return mysqli_fetch_row($res); } function fetchAssoc($res) { return mysqli_fetch_assoc($res); } function freeRes($res) { return mysqli_free_result($res); } function selectLimit($sql, $length = null, $offset = null) { if (!is_null($offset)) { $sql .= " LIMIT " . (int)$offset; if (!is_null($length)) { $sql .= ', ' . (int)$length; } else { $sql .= ', 4294967294'; } } elseif (!is_null($length)) { $sql .= " LIMIT " . (int)$length; } return $this->execute($sql); } function metaColumns($table) { /** * C CHAR 或 VARCHAR 类型字段 * X TEXT 或 CLOB 类型字段 * B 二进制数据(BLOB) * N 数值或者浮点数 * D 日期 * T TimeStamp * L 逻辑布尔值 * I 整数 * R 自动增量或计数器 */ static $typeMap = array( 'BIT' => 'I', 'TINYINT' => 'I', 'BOOL' => 'L', 'BOOLEAN' => 'L', 'SMALLINT' => 'I', 'MEDIUMINT' => 'I', 'INT' => 'I', 'INTEGER' => 'I', 'BIGINT' => 'I', 'FLOAT' => 'N', 'DOUBLE' => 'N', 'DOUBLEPRECISION' => 'N', 'FLOAT' => 'N', 'DECIMAL' => 'N', 'DEC' => 'N', 'DATE' => 'D', 'DATETIME' => 'T', 'TIMESTAMP' => 'T', 'TIME' => 'T', 'YEAR' => 'I', 'CHAR' => 'C', 'NCHAR' => 'C', 'VARCHAR' => 'C', 'NVARCHAR' => 'C', 'BINARY' => 'B', 'VARBINARY' => 'B', 'TINYBLOB' => 'X', 'TINYTEXT' => 'X', 'BLOB' => 'X', 'TEXT' => 'X', 'MEDIUMBLOB' => 'X', 'MEDIUMTEXT' => 'X', 'LONGBLOB' => 'X', 'LONGTEXT' => 'X', 'ENUM' => 'C', 'SET' => 'C', ); $rs = $this->execute(sprintf($this->META_COLUMNS_SQL, $table)); if (!$rs) { return false; } $retarr = array(); while (($row = mysqli_fetch_assoc($rs))) { $field = array(); $field['name'] = $row['Field']; $type = $row['Type']; $field['scale'] = null; $queryArray = false; if (preg_match('/^(.+)\((\d+),(\d+)/', $type, $queryArray)) { $field['type'] = $queryArray[1]; $field['maxLength'] = is_numeric($queryArray[2]) ? $queryArray[2] : -1; $field['scale'] = is_numeric($queryArray[3]) ? $queryArray[3] : -1; } elseif (preg_match('/^(.+)\((\d+)/', $type, $queryArray)) { $field['type'] = $queryArray[1]; $field['maxLength'] = is_numeric($queryArray[2]) ? $queryArray[2] : -1; } elseif (preg_match('/^(enum)\((.*)\)$/i', $type, $queryArray)) { $field['type'] = $queryArray[1]; $arr = explode(",",$queryArray[2]); $field['enums'] = $arr; $zlen = max(array_map("strlen",$arr)) - 2; // PHP >= 4.0.6 $field['maxLength'] = ($zlen > 0) ? $zlen : 1; } else { $field['type'] = $type; $field['maxLength'] = -1; } $field['simpleType'] = $typeMap[strtoupper($field['type'])]; // if ($field['simpleType'] == 'C' && $field['maxLength'] > 250) { // $field['simpleType'] = 'X'; // } $field['notNull'] = ($row['Null'] != 'YES'); $field['primaryKey'] = ($row['Key'] == 'PRI'); $field['autoIncrement'] = (strpos($row['Extra'], 'auto_increment') !== false); if ($field['autoIncrement']) { $field['simpleType'] = 'R'; } $field['binary'] = (strpos($type,'blob') !== false); $field['unsigned'] = (strpos($type,'unsigned') !== false); if ($field['type'] == 'tinyint' && $field['maxLength'] == 1) { $field['simpleType'] = 'L'; } if (!$field['binary']) { $d = $row['Default']; if ($d != '' && $d != 'NULL') { $field['hasDefault'] = true; $field['defaultValue'] = $this->setValueByType($d, $field['simpleType']); } else { $field['hasDefault'] = false; } } $field['description'] = isset($row['Comment']) ? $row['Comment'] : ''; $retarr[strtoupper($field['name'])] = $field; } mysqli_free_result($rs); return $retarr; } function metaTables($pattern = null, $schema = null) { $sql = 'SHOW TABLES'; if (!empty($schema)) { $sql .= " FROM {$schema}"; } if (!empty($pattern)) { $sql .= ' LIKE ' . $this->qstr($schema); } $res = $this->execute($sql, null, false); $tables = array(); while (($row = $this->fetchRow($res))) { $tables[] = reset($row); } $this->freeRes($res); return $tables; } function _startTrans() { $this->execute('START TRANSACTION'); } function _completeTrans($commitOnNoErrors = true) { if ($this->_hasFailedQuery == false && $commitOnNoErrors) { $this->execute('COMMIT'); } else { $this->execute('ROLLBACK'); } } }

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Evaluating the cost/performance of commercial support for a Java framework involves the following steps: Determine the required level of assurance and service level agreement (SLA) guarantees. The experience and expertise of the research support team. Consider additional services such as upgrades, troubleshooting, and performance optimization. Weigh business support costs against risk mitigation and increased efficiency.

The learning curve of a PHP framework depends on language proficiency, framework complexity, documentation quality, and community support. The learning curve of PHP frameworks is higher when compared to Python frameworks and lower when compared to Ruby frameworks. Compared to Java frameworks, PHP frameworks have a moderate learning curve but a shorter time to get started.

The lightweight PHP framework improves application performance through small size and low resource consumption. Its features include: small size, fast startup, low memory usage, improved response speed and throughput, and reduced resource consumption. Practical case: SlimFramework creates REST API, only 500KB, high responsiveness and high throughput

According to benchmarks, for small, high-performance applications, Quarkus (fast startup, low memory) or Micronaut (TechEmpower excellent) are ideal choices. SpringBoot is suitable for large, full-stack applications, but has slightly slower startup times and memory usage.

Writing clear and comprehensive documentation is crucial for the Golang framework. Best practices include following an established documentation style, such as Google's Go Coding Style Guide. Use a clear organizational structure, including headings, subheadings, and lists, and provide navigation. Provides comprehensive and accurate information, including getting started guides, API references, and concepts. Use code examples to illustrate concepts and usage. Keep documentation updated, track changes and document new features. Provide support and community resources such as GitHub issues and forums. Create practical examples, such as API documentation.

Choose the best Go framework based on application scenarios: consider application type, language features, performance requirements, and ecosystem. Common Go frameworks: Gin (Web application), Echo (Web service), Fiber (high throughput), gorm (ORM), fasthttp (speed). Practical case: building REST API (Fiber) and interacting with the database (gorm). Choose a framework: choose fasthttp for key performance, Gin/Echo for flexible web applications, and gorm for database interaction.

In Go framework development, common challenges and their solutions are: Error handling: Use the errors package for management, and use middleware to centrally handle errors. Authentication and authorization: Integrate third-party libraries and create custom middleware to check credentials. Concurrency processing: Use goroutines, mutexes, and channels to control resource access. Unit testing: Use gotest packages, mocks, and stubs for isolation, and code coverage tools to ensure sufficiency. Deployment and monitoring: Use Docker containers to package deployments, set up data backups, and track performance and errors with logging and monitoring tools.

There are five misunderstandings in Go framework learning: over-reliance on the framework and limited flexibility. If you don’t follow the framework conventions, the code will be difficult to maintain. Using outdated libraries can cause security and compatibility issues. Excessive use of packages obfuscates code structure. Ignoring error handling leads to unexpected behavior and crashes.
