LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 06-22-2018, 01:13 PM   #1
TBotNik
Member
 
Registered: May 2016
Location: Greenville, TX
Distribution: Kubuntu 18.04
Posts: 796

Rep: Reputation: Disabled
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
 
Old 06-23-2018, 10:50 AM   #2
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
Quote:
Originally Posted by TBotNik View Post
do I use the same logic
that is shown for the PostGres connection processing.
Yes, give it a try. Sorry can't tell much without seeing context, how the function is used etc... I fail to see what $conn use is for as it is not seen elsewhere in the function.
 
Old 06-25-2018, 04:01 PM   #3
TBotNik
Member
 
Registered: May 2016
Location: Greenville, TX
Distribution: Kubuntu 18.04
Posts: 796

Original Poster
Rep: Reputation: Disabled
Solved! Not Really but works

All,

So due to lack of direct "fix it" responses, I used the same logic from the PostGres section to fix this.

Not what I wanted but it works!

Marking this solved!

Cheers!

OMR/TBNK
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] PHP / MySQLI display results pr0xibus Programming 2 06-17-2014 02:27 PM
Help me to disable mysqli in php kaviajan Linux - Server 1 09-25-2012 04:46 AM
php mysqli::connection must stay in scope? sogenant Programming 2 07-10-2008 08:57 PM
Php and MySQL Whats this New stuff (Mysqli)? helptonewbie Linux - Newbie 5 04-04-2008 10:59 AM
apache 2.0 + PHP 5 + mysql AND mysqli? nyttoc Linux - Server 1 05-08-2007 08:28 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 11:14 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration