Mysqli connection extension in FLEAPHP framework

Source: Internet
Author: User
The company's old CRM system is based on FLEAPHP, which is not updated for a long time. When php is upgraded to 5.5, the system will prompt that the mysql_connect function is about to be discarded. It is recommended to change to mysqli or pdo, does nnd force me to change the framework? Well, I just want to talk about it, but I should do it myself. Add a new Mysqli. php file and modify the Abstract. php file. User

The company's old CRM system is based on FLEAPHP, which is not updated for a long time. When php is upgraded to 5.5, the system will prompt that the mysql_connect function is about to be discarded. It is recommended to change to mysqli or pdo, does nnd force me to change the framework? Well, I just want to talk about it, but I should do it myself. Add a new Mysqli. php file and modify the Abstract. php file. User

The company's old CRM system is based on FLEAPHP, which is not updated for a long time. When php is upgraded to 5.5, the system will prompt that the mysql_connect function is about to be discarded. It is recommended to change to mysqli or pdo, does nnd force me to change the framework? Well, I just want to talk about it, but I should do it myself.
Add a new Mysqli. php file and modify the Abstract. php file.
Usage:
Put the two files in the "FLEA \ Db \ Driver \" directory and overwrite them.
Ps: Abstract. php only makes a small modification to compatibility without affecting other functions. FleaPHP
 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) {r Eturn $ 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 selec TLimit ($ 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 or VARCHAR type field * x text or CLOB type field * B binary data (BLOB) * N value or floating point number * D date * T TimeStamp * L logical Boolean value * I integer * R automatic increment or counter */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 ['nums'] = $ 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 ['autocredentials'] = (strpos ($ row ['extra '], 'Auto _ credentials ')! = False); if ($ field ['autosecret']) {$ field ['simpletype'] = 'R ';} $ field ['binary '] = (strpos ($ type, 'blob ')! = False); $ field ['unsigne'] = (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 variables Ables ($ 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 ');}}}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.