Home Products Downloads News Store Support

Stan's Blog

MLM mySQL to mySQLi migration

How to use Maxprog products Maxprog's Blog

Compatible with MS Windows Compatible with MacOS


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






Stan Busk Stan Busk
January 10, 2019






Recent questions from our users
  How to import a Bank statement into iCash NEW YouTube Video
  Is Maxprog software prepared for macOS 11 Big Sur? NEW Screenshot
  How to transfer email lists between MaxBulk Mailer copies NEW Screenshot
  How can I download files with sequential numbers in their name? NEW YouTube Video
  Images are missing in the message preview NEW Screenshot
  How to send an email with a picture in the body NEW YouTube Video
  Mail-merge sender data using tags NEW YouTube Video
  I set up my bulk email message but authentication fails NEW YouTube Video
  How can I send Base64 encoded messages with MaxBulk Mailer? NEW YouTube Video
  How do I use Mandrill for sending emails NEW Screenshot
  Emails not delivered despite successful delivery report NEW YouTube Video
  Do I need a mail server account to use MaxBulk Mailer? UPDATED YouTube Video
  How can I validate Hotmail and Gmail email addresses? UPDATED Screenshot
  I have bought a new computer, how do I transfer the license? UPDATED YouTube Video
  Ha desaparecido mi contabilidad de iCash UPDATED Screenshot

  [Valid RSS]  Subscribe to Maxprog's Knowledge Base



Did you like this post?


   
🔐 Site secured by Comodo SSL
  🟢 UptimeRobot - Site Loaded properly