Sponsored Content
Full Discussion: Transistion to php mysqli
Operating Systems Linux Transistion to php mysqli Post 303019074 by TBotNik on Friday 22nd of June 2018 01:53:59 PM
Old 06-22-2018
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; 06-22-2018 at 03:11 PM..
 

5 More Discussions You Might Find Interesting

1. Web Development

I can't open my index.php page after insert php code

Hello guys, Does anyone can help me? I've just made my simple index.php without any code, but after insert session code to check if any user is authenticated, my index.php doesn't work anymore. Any fresh eyes could help me to see what and where the code is wrong? <? if... (6 Replies)
Discussion started by: metalfreakbr
6 Replies

2. UNIX for Advanced & Expert Users

Running multiple php scripts into one php only, cron mail alert problem...

hi, while separated they produce the usual mail alert and i can see the output... if i write into the php script: <?php system('php -f /var/www/vhosts/domain.com/httpdocs/folder/script1.php'); system('php -f /var/www/vhosts/domain.com/httpdocs/folder/script2.php'); system('php -f... (0 Replies)
Discussion started by: 7stars
0 Replies

3. Red Hat

Update php 4.3 RPM to php 5.3.3 php

Dear All, My redhat version is: # cat /etc/redhat-release Red Hat Enterprise Linux AS release 4 (Nahant Update 4) # # uname -a Linux cotapplication3.cot.com 2.6.9-42.ELsmp #1 SMP Wed Jul 12 23:32:02 EDT 2006 x86_64 x86_64 x86_64 GNU/Linux # I want to update my php from: # php... (1 Reply)
Discussion started by: monojcool
1 Replies

4. Shell Programming and Scripting

Running php index.php as shell in webpage

so i have a bit of a unique situation. i have an encrypted index.php file that that can't be run the normal way that a web browser would run it. if it is run the normal way, the php script will show only gibberish on the web browser, instead of the actual php code. when run from the command... (8 Replies)
Discussion started by: SkySmart
8 Replies

5. What is on Your Mind?

Saturday May 4th the Forums Will Briefly Break Testing PHP 5.6 to PHP 7.0

On Saturday May 4th the forums will briefly break when I switch our Apache PHP 5.6 module to PHP 7.0. Previously, I had two sites set up for testing the migration, but for many reasons, the second site has additional issues unrelated to PHP 7.0 so it is hard to debug on a different site and... (3 Replies)
Discussion started by: Neo
3 Replies
All times are GMT -4. The time now is 09:13 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy