Sunday, 15 May 2011

The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead -



The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead -

this question has reply here:

why shouldn't utilize mysql_* functions in php? 10 answers

when effort connect mysql server php, see next error:

deprecated: mysql extension deprecated , removed in future: utilize mysqli or pdo instead in /path/to/filename.php on line 123

the code on referenced line is:

mysql_connect($server, $username, $password);

i arguments correct, , exact code has been working years without problem. indeed, obtained well-sourced tutorial on php.

why happening?

how can prepare it?

i understand it's possible suppress deprecation errors setting error_reporting in php.ini exclude e_deprecated:

error_reporting = e_all ^ e_deprecated

what happen if that?

why happening?

the entire ext/mysql php extension, provides functions named prefix mysql_, officially deprecated of php v5.5.0 , removed in future.

it introduced in php v2.0 (november 1997) mysql v3.20, , no new features have been added since 2006. coupled lack of new features difficulties in maintaining such old code amidst complex security vulnerabilities.

the manual has contained warnings against utilize in new code since june 2011.

how can prepare it?

as error message suggests, there 2 other mysql extensions can consider: mysqli , pdo_mysql, either of can used instead of ext/mysql. both have been in php core since v5.0, if you're using version throwing these deprecation errors can start using them right away—i.e. without installation effort.

they differ slightly, offer number of advantages on old extension including api back upwards transactions, stored procedures , prepared statements (thereby providing the best way defeat sql injection attacks). php developer ulf wendel has written a thorough comparing of features.

hashphp.org has excellent tutorial on migrating ext/mysql pdo.

i understand it's possible suppress deprecation errors setting error_reporting in php.ini exclude e_deprecated:

error_reporting = e_all ^ e_deprecated

what happen if that?

yes, possible suppress such error messages , go on using old ext/mysql extension time being. you shouldn't this—this final warning developers extension may not bundled future versions of php (indeed, it has been removed php v7). instead, should take chance migrate application now, before it's late.

note technique suppress all e_deprecated messages, not ext/mysql extension: hence may unaware of other upcoming changes php impact application code. is, of course, possible suppress errors arise on look @ issue using php's error command operator—i.e. prepending relevant line @—however suppress all errors raised expression, not e_deprecated ones.

what should do?

you starting new project.

there absolutely no reason utilize ext/mysql—choose 1 of other, more modern, extensions instead , reap rewards of benefits offer.

you have (your own) legacy codebase depends upon ext/mysql.

it wise perform regression testing: shouldn't changing anything (especially upgrading php) until have identified of potential areas of impact, planned around each of them , thoroughly tested solution in staging environment.

following coding practice, application developed in loosely integrated/modular fashion , database access methods self-contained in 1 place can swapped out 1 of new extensions.

spend half hr rewriting module utilize 1 of other, more modern, extensions; test thoroughly. can later introduce farther refinements reap rewards of benefits offer.

the database access methods scattered on place , cannot swapped out 1 of new extensions.

consider whether need upgrade php v5.5 @ time.

you should begin planning replace ext/mysql 1 of other, more modern, extensions in order can reap rewards of benefits offer; might utilize chance refactor database access methods more modular structure.

however, if have urgent need upgrade php right away, might consider suppressing deprecation errors time being: first sure identify other deprecation errors beingness thrown.

you using 3rd party project depends upon ext/mysql.

consider whether need upgrade php v5.5 @ time.

check whether developer has released fixes, workarounds or guidance in relation specific issue; or, if not, pressure level them bringing matter attention. if have urgent need upgrade php right away, might consider suppressing deprecation errors time being: first sure identify other deprecation errors beingness thrown.

it absolutely essential perform regression testing.

mysql deprecated php

No comments:

Post a Comment