Home Products Downloads News Store Support Forums

Stan's Blog

Stan's Blog

Tips and tricks on how to use Maxprog products

Compatible with MS Windows Compatible with MacOS

 Share this page! 

MLM mySQL to mySQLi migration

Topics
MLM has been fully updated to use mySQLi calls rather than mySQL.

That was done during summer 2016 and fully tested during 12 months for problems. None were found so the procedure below is quite secure. If you read this and you are about to update your PHP file to use mySQLi calls the best is to prepare you work thoroughly in advance. Check which functions are used and what is the mySQLi equivalent, the name use to be the same but with a mysqli_ prefix instead of mysql_ however most function calls require more parameters to be passed and they can be in reverse order.

List of MySQL functions to update (in lm_functions.php):

> mysql_get_host_info()
--> mysqli_get_host_info ( $mysql_link )

> mysql_get_server_info()
--> mysqli_get_server_info ( $mysql_link )

> mysql_get_client_info()
--> mysqli_get_client_info ( $mysql_link )

> mysql_get_proto_info()
--> mysqli_get_proto_info ( $mysql_link )

> mysql_real_escape_string( $text )
--> mysqli_real_escape_string ( $mysql_link , $text )

> mysql_affected_rows( $mysql_link )
--> mysqli_affected_rows ( $mysql_link )

> mysql_client_encoding( $mysql_link )
--> mysqli_character_set_name ( $mysql_link )

> mysql_close( $mysql_link )
--> mysqli_close($mysql_link)

> mysql_connect( $dbhost, $dbusername, $dbuserpass, $dbname )
--> mysqli_connect( $dbhost, $dbusername, $dbuserpass, $dbname )

> mysql_db_query( $dbname, $query )
--> mysqli_query( $mysql_link, $query )

> mysql_errno( $mysql_link )
--> mysqli_errno( $mysql_link )

> mysql_error( $mysql_link )
--> mysqli_error( $mysql_link )

> mysql_fetch_array( $res )
--> mysqli_fetch_array( $res )

> mysql_num_rows( $res )
--> mysqli_num_rows( $res )

> mysql_query( $query, $mysql_link )
--> mysqli_query( $mysql_link, $query ) <- INVERTED PARAMETERS!!

> mysql_select_db ( $dbname )
--> NOT REQUIRED, SEE NOTE 3

> mysql_set_charset( "utf8", $mysql_link )
--> mysqli_set_charset( $mysql_link, "utf8" ) <- INVERTED PARAMETERS!!

> mysql_fetch_object( $res )
--> mysqli_fetch_object ( $res )

Server connection error has changed:

> mysql_errno( $mysql_link )
--> mysqli_connect_errno()

> mysql_error( $mysql_link )
--> mysqli_connect_error()

NOTE 1: $mysql_link has to be global and available to each function that needs it with the 'global' keyword.

NOTE 2: After a given query has been processed and we are done with the result just call the mysqli_free_result($result) function.

NOTE 3: mysqli_connect already select the database so mysqli_select_db ( $mysql_link , $dbname ) is just for changing DB.

After the changes we should not find any 'mysql_' strings in the code at all.

For your info, the mysqli extension has a number of benefits, the key enhancements over the mysql extension being:

- Object-oriented interface
- Support for Prepared Statements
- Support for Multiple Statements
- Support for Transactions
- Enhanced debugging capabilities
- Embedded server support

Manual | Migration guide | Guide + tool | More info


Stan Busk - Software Engineer
at www.maxprog.com





Did you like this post? Share it!


Generic questions
New paragraph
How do I install Maxprog software on my computer?
macOS
MS Windows
New paragraph
How can I change an application language?
macOS
MS Windows
New paragraph
How to register the software I've just purchased?
macOS
MS Windows
New paragraph
How can I recover the serials I have lost of products I purchased here?
macOS
MS Windows
New paragraph
How can I recover my serial from a registered application?
macOS
MS Windows
New paragraph
How can I find out the product name and version my serial unlocks?
macOS
MS Windows
New paragraph
Where can I read your software License Agreement?
macOS
MS Windows
New paragraph
The software doesn't start, runs very slowly or crashes often, how comes?
macOS
MS Windows
New paragraph
Double-clicking on my files no longer opens them with the software, why?
macOS
MS Windows
Stan Busk If you want to make the most of the software that you have acquired at Maxprog, do not miss the Stan's Blog. It is a library of Tutorials and Tips covering specific features and tipical problems you may have when using our tools. This page is updated regularly depending on the topics discussed in our public forums and issues reported thru our HelpDesk. If you are interested on what we are currently working on (or want to participate in beta testings) don't miss the Stan's Logbook.
For years, MAX Programming has provided companies around the globe with sophisticated and innovative solutions. Our commitment to quality is not only evident in our products, but also in our people. It is our mission in Professional Support Services to ensure that our products perform to the fullest of their ability in order to meet the business objectives of our customers. We provide the tools and information required for improved productivity. To accomplish this, we offer an array of services including: Technical Support, Education Services and Consulting Services.

Maxprog is part of an internet site network made of desktoolset.com, emaildesignstudio.com, familycash.com, icash.promo, maxbulkmailer.com, maxprog.com, maxprog.net, maxprog.org, maxprog.us, myrecipients.com, newslettercomposer.com, sharedcontents.com, stanbusk.com, stanbusk.pairserver.com, usertools.com.

 !  WAIT! In order to add a comment below just use your Facebook, Google, Twitter or Disqus login data.

Home Products Downloads News Store Support Forums