Linux

RedHat, Ubuntu, SUSE, Fedora, Debian, Mandriva, Slackware, Gentoo linux, PCLinuxOS. All Linux questions here!

Transistion to php mysqli


👤 Login to reply

    #1  
Old 4 Weeks Ago
TBotNik TBotNik is offline
Registered User
 
Join Date: Jun 2018
Last Activity: 21 July 2018, 12:43 PM EDT
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Transistion to php mysqli

All,

I'm using the Enterprise Modules Framework (Tomorrow's Framework) and the recent
changes/upgrades to PHP7 require the use of mysqli_ commands over the old mysql_
commands. Here is the code from the connection section of the dataio module:

Code:
         function dbConnect($eng,$hst,$udb,$usr,$pwd) {
           /*********************************************************************/
           /*  Function: dbConnect()                                            */
           /*      Call: dbCommect ( eng, host, usedb, user, pwd )                    */
           /*   Purpose: Connects the database & reports errors.  Only one      */
           /*            consecutive connection allowed.                                */
           /*********************************************************************/
           //self::db_Set_Vars ($eng,$hst,$udb,$usr,$pwd,'','','');
            if ( $de_bug    == 5 ) {
                echo "DE=> $eng <br>\n";
                echo "DH=> $hst <br>\n";
                echo "DU=> $udb <br>\n";
                echo "DL=> $usr <br>\n";
                echo "DP=> $pwd <br>\n";
            }    // end if $de_bug
           /*if ( isset ( $_SESSION['DB_CON']) && $_SESSION['DB_CON']<>NULL ) { 
              $this->db_con    =    $_SESSION['DB_CON'];
           } else {
              $this->db_con    =    DB_CON;
           }  // end if/else $_SESSION['db_usr'] */
           if (!$con) {
              switch ($eng) {
                    case 'ingres':                // Process using the Ingres Engine
                        //    TBD                    // Ingres user your contribution please
                        break;
                     case 'mssql':                // Process using the MS-SQL Engine
                         //    TBD                    // MS-SQL user your contribution please
                         break;
                 case 'mysql':            // Process MySQL Engine
                        $ver        =    intval ( phpversion () );
                        if ( $ver < 7 ) {
                            $conn     =    mysql_connect($hst,$usr,$pwd) or die(mysql_error());
                            $seldb    =    mysql_select_db($udb,$conn) or die(mysql_error());
                          $this->db_sel = false;
                           if ($seldb) { $this->db_sel = true; }
                        } else {
                            $conn = new mysqli($hst,$usr,$pwd,$udb) or die(mysql_error());
                        }
                          break;
                    case 'pgsql':            // Process PostGres Engine
                       $con_str       =  "host=$db_hst port=$db_prt user=$db_uid ".
                                    "password=$db_pwd dbname=$db_nam"; 
                       $this->db_con = pg_connect($con_str) 
                           or die("Error: Failed to connect with CONN_STRING");
                       if ($this->db_con) {
                          $this->db_sel = true;
                       } else {
                          $this->db_sel = false;
                       }  // end if $this->db_con
                       break;
                     case 'oracle':            // Process using the Oracle Engine
                         //    TBD                    // Oracle user your contribution please
                         break;
                     case 'sybase':            // Process using the SyBase Engine
                         //    TBD                    // SyBase user your contribution please
                         break;
              }  // end switch
           }     // end if !$this->con
            if ($this->db_sel === true) {
                return array($this->db_con, $this->db_use);
            }  // end if $this->con
        }     // end function dbConnect

You can see why I use EM as you can trancend and/0r interpose on any DB. I once
had all the code for MS-SQL and Oracle, when on a client project where they were
using both as their DBs and they couldn't understand why I could merge databases
so easy, but you can when all the code is the same and you just choose the DB
engine.

Anyway the problem is all previous code and all the other code is looking for the
$this->db_sel var to be set "TRUE" when actually connected and the DB selected.
All the HOWTOs and code samples do not show a way to get this, without writing a
complex query.


Version is queried at the lines:
Code:
 $ver        =    intval ( phpversion () );
                        if ( $ver < 7 ) {

I need to know if there is a simple command on this, or do I use the same logic
that is shown for the PostGres connection processing.

Just need to know to keep this optimized as possible.

Cheers!

OMR/TBNK

Last edited by TBotNik; 4 Weeks Ago at 02:11 PM..
Sponsored Links
    #2  
Old 4 Weeks Ago
Neo's Unix or Linux Image
Neo Neo is offline Forum Staff  
Administrator
 
Join Date: Sep 2000
Last Activity: 21 July 2018, 2:42 PM EDT
Location: Asia pacific region
Posts: 14,579
Thanks: 1,032
Thanked 1,438 Times in 698 Posts
You can also try this:

Code:
<?php
if (version_compare(phpversion(), '5.3.10', '<')) {
    // php version isn't high enough
}
?>

Or something like this:

Code:
<?php
$ver = (float)phpversion();
if ($ver > 7.0) {
    //do something for php7.1 and above.
} elseif ($ver === 7.0) {
    //do something for php7.0
} else {
    //do something for php5.6 or lower.
}
?>

Sponsored Links
    #3  
Old 3 Weeks Ago
TBotNik TBotNik is offline
Registered User
 
Join Date: Jun 2018
Last Activity: 21 July 2018, 12:43 PM EDT
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by Neo View Post
You can also try this:

Code:
<?php
if (version_compare(phpversion(), '5.3.10', '<')) {
    // php version isn't high enough
}
?>

Or something like this:

Code:
<?php
$ver = (float)phpversion();
if ($ver > 7.0) {
    //do something for php7.1 and above.
} elseif ($ver === 7.0) {
    //do something for php7.0
} else {
    //do something for php5.6 or lower.
}
?>

Neo, The test code I used is fine as all version prior to 7 can use the old code, but 7.0 and greater mysqli only, so my test is good. My Q wasn't about the version, got that down, it the return, showing the DB acked for is actually in play. I'm closing this, because due to lack of "fix it" responses, went with the same logic used in the PostGres section, since the open statement now requires the used DB as part of the open statement string. Thanks anyway! Cheers! OMR/TBNK
    #4  
Old 3 Weeks Ago
Neo's Unix or Linux Image
Neo Neo is offline Forum Staff  
Administrator
 
Join Date: Sep 2000
Last Activity: 21 July 2018, 2:42 PM EDT
Location: Asia pacific region
Posts: 14,579
Thanks: 1,032
Thanked 1,438 Times in 698 Posts
We also have the same problem with transitioning these forums to PHP7 and mysqli from legacy versions of PHP.

It's a lot of work and I've not had time to do it because of other projects.
Sponsored Links
    #5  
Old 3 Weeks Ago
TBotNik TBotNik is offline
Registered User
 
Join Date: Jun 2018
Last Activity: 21 July 2018, 12:43 PM EDT
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
EM Dataio

Quote:
Originally Posted by Neo View Post
We also have the same problem with transitioning these forums to PHP7 and mysqli from legacy versions of PHP.

It's a lot of work and I've not had time to do it because of other projects.
You might want a copy of the EM dataio modules for this! That's what I'm fixing now! Cheers! OMR?TBNK
Sponsored Links
👤 Login to reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Update php 4.3 RPM to php 5.3.3 php monojcool Red Hat 1 04-26-2013 01:31 PM
Running multiple php scripts into one php only, cron mail alert problem... 7stars UNIX for Advanced & Expert Users 0 11-14-2011 04:49 AM



All times are GMT -4. The time now is 07:24 PM.

Unix & Linux Forums Content Copyrightę1993-2018. All Rights Reserved.
×
UNIX.COM Login
Username:
Password:  
Show Password





Not a Forum Member?
Forgot Password?