Post by knight_47 » Thu Feb 25, 2016 10:53 am

First of all thanks in advance for looking over this, I'm kind of in a dire situation here regarding one of my fathers sites:

Code: Select all

abmedsupply.com
I'm having a pretty big issue at the moment, my host (Dreamhost) recently upgraded from php 5.3 to 5.7, i'm running OC 1.5.6, which apparently won't run on php 5.7.

I get an error on the top of the site:

Code: Select all

Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /home/riad/abmedsupply.com/system/database/mysql.php on line 6
And when accessing the /admin panel, it shows up, but once logging in it comes up with this error:

Code: Select all

Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /home/riad/abmedsupply.com/system/database/mysql.php on line 6
Warning: Cannot modify header information - headers already sent by (output started at /home/riad/abmedsupply.com/system/database/mysql.php:6) in /home/riad/abmedsupply.com/vqmod/vqcache/vq2-system_engine_controller.php on line 28Warning: Cannot modify header information - headers already sent by (output started at /home/riad/abmedsupply.com/system/database/mysql.php:6) in /home/riad/abmedsupply.com/vqmod/vqcache/vq2-system_engine_controller.php on line 29
With no way for me to get to the back end.

Is there anyway I can solve this, or possible upgrade my opencart install to OC 2 even which would support php 5.7?

I have several products, categories, and custom options, extension, SEO extensions, etc which would defiitely need to be retained.

Any help at on how to solve this at all would be greatly appreciated. Thank you again.

New member

Posts

Joined
Fri Mar 11, 2011 2:45 pm

Post by ocart777 » Thu Feb 25, 2016 11:01 am

root/config.php
root/admin/config.php

instead of

Code: Select all

define('DB_DRIVER', 'mysql');
use

Code: Select all

define('DB_DRIVER', 'mysqli');

You can't control the weather, but you can change your mood.
You can't modify the visage, but you can show your smile.
You can't command someone else, but you can hold yourself.
You can't forecast tomorrow, but you can using today.
You can't obtain thanks, but you can exert yourself in everything.


OCEXTENSION.COM - YOUR PROFESSIONAL OPENCART EXTENSION STORE


User avatar
Active Member

Posts

Joined
Mon Jun 10, 2013 4:57 pm
Location - Malaysia

Post by knight_47 » Thu Feb 25, 2016 11:07 am

ocart777 wrote:root/config.php
root/admin/config.php

instead of

Code: Select all

define('DB_DRIVER', 'mysql');
use

Code: Select all

define('DB_DRIVER', 'mysqli');
Just did that for both the /config and /admin/config/php files and now I get this error with no site loading at all:

Code: Select all

Parse error: syntax error, unexpected 'else' (T_ELSE), expecting function (T_FUNCTION) in /home/riad/abmedsupply.com/system/database/mysqli.php on line 54
Thank you for the suggestion though.

Do I need to edit anything on my hostings end?

New member

Posts

Joined
Fri Mar 11, 2011 2:45 pm

Post by ocart777 » Thu Feb 25, 2016 12:12 pm

and whats on the line 54 are of that file?

You can't control the weather, but you can change your mood.
You can't modify the visage, but you can show your smile.
You can't command someone else, but you can hold yourself.
You can't forecast tomorrow, but you can using today.
You can't obtain thanks, but you can exert yourself in everything.


OCEXTENSION.COM - YOUR PROFESSIONAL OPENCART EXTENSION STORE


User avatar
Active Member

Posts

Joined
Mon Jun 10, 2013 4:57 pm
Location - Malaysia

Post by knight_47 » Thu Feb 25, 2016 12:21 pm

line 54 specifically:

Code: Select all

		} else {
the whole mysqli.php file:

Code: Select all

<?php
final class MySQLi {
	private $mysqli;
	
	public function __construct($hostname, $username, $password, $database) {
		$this->mysqli = new mysqli($hostname, $username, $password, $database);
		
		if ($this->mysqli->connect_error) {
      		trigger_error('Error: Could not make a database link (' . $this->mysqli->connect_errno . ') ' . $this->mysqli->connect_error);
		}
		
		$this->mysqli->query("SET NAMES 'utf8'");
		$this->mysqli->query("SET CHARACTER SET utf8");
		$this->mysqli->query("SET CHARACTER_SET_CONNECTION=utf8");
		$this->mysqli->query("SET SQL_MODE = ''");
  	}
		
  	public function query($sql) {
		$result = $this->mysqli->query($sql);

		

		if ($this->mysqli->errno) {
		//$mysqli->errno
		}
		
			if (is_resource($resource)) {
				$i = 0;
    	
				$data = array();
		
				while ($row = $result->fetch_object()) {
					$data[$i] = $row;
    	
					$i++;
				}

				$result->close();
				
				$query = new stdClass();
				$query->row = isset($data[0]) ? $data[0] : array();
				$query->rows = $data;
				$query->num_rows = $result->num_rows;
				
				unset($data);
				
				
				
				
				return $query;	
    		} else {
				return true;
			}
		} else {
			trigger_error('Error: ' . mysql_error($this->link) . '<br />Error No: ' . mysql_errno($this->link) . '<br />' . $sql);
			exit();
    	}
  	}
	
	public function escape($value) {
		return $this->mysqli->real_escape_string($value);
	}
	
  	public function countAffected() {
    	return $this->mysqli->affected_rows;
  	}

  	public function getLastId() {
    	return $this->mysqli->insert_id;
  	}	
	
	public function __destruct() {
		$this->mysqli->close();
	}
}
?>
Which does appear to be some sort of syntax error, but i'm not exactly a php expert here, thanks again for your time and help.

New member

Posts

Joined
Fri Mar 11, 2011 2:45 pm

Post by ocart777 » Thu Feb 25, 2016 12:49 pm

give this a try, anyway your code looks similar to OC v1.5.5

Code: Select all

    public function query($sql) {
      $result = $this->mysqli->query($sql);
	  
      if (!$this->mysqli->errno) {
      
         if (is_resource($resource)) {
            $i = 0;
       
            $data = array();
      
            while ($row = $result->fetch_object()) {
               $data[$i] = $row;
       
               $i++;
            }
			
            $result->close();
            
            $query = new stdClass();
            $query->row = isset($data[0]) ? $data[0] : array();
            $query->rows = $data;
            $query->num_rows = $result->num_rows;
            
            unset($data);
            
            
            
            
            return $query;   
          } else {
            return true;
          }
      } else {
         trigger_error('Error: ' . mysql_error($this->link) . '<br />Error No: ' . mysql_errno($this->link) . '<br />' . $sql);
         exit();
      }
    }

You can't control the weather, but you can change your mood.
You can't modify the visage, but you can show your smile.
You can't command someone else, but you can hold yourself.
You can't forecast tomorrow, but you can using today.
You can't obtain thanks, but you can exert yourself in everything.


OCEXTENSION.COM - YOUR PROFESSIONAL OPENCART EXTENSION STORE


User avatar
Active Member

Posts

Joined
Mon Jun 10, 2013 4:57 pm
Location - Malaysia

Post by knight_47 » Mon Feb 29, 2016 1:25 am

I really appreciate your help here. I'm a little confused here, is that code suppose to replace the whole /systems/database/mysqli.php file? I just replaced your code with my mysqli.php code, and it came up with additional errors.

Any other ideas?

New member

Posts

Joined
Fri Mar 11, 2011 2:45 pm

Post by IP_CAM » Mon Feb 29, 2016 2:08 am

in my OC v.1.5.6.4+, I only have ONE Admin 'OpenShop' Extension 'Source File Editor', and if trying to execute it, it's producing a full page Server Error, with some 'illegal type compression message' coming from PHP 5.7, so, I had to re-define a lower PHP Version on the Server, to make it work again, for the time beeing, at least, because I really like this fine Code Editor, and would like to keep 'em.
--
It would be rather interesting, to find out, how older OC 'Programs' can be upmodded, in a way, possibly,
someone around here know's more about this.
---
Here are 4 different Files, to test, the TOP ONE is called:
mysqli.php
define('DB_DRIVER', 'mysqli');

Code: Select all

<?php
final class DBMySQLi {
	private $link;

	public function __construct($hostname, $username, $password, $database) {
		$this->link = new mysqli($hostname, $username, $password, $database);

		if (mysqli_connect_error()) {
			throw new ErrorException('Error: Could not make a database link (' . mysqli_connect_errno() . ') ' . mysqli_connect_error());
		}

		$this->link->set_charset("utf8");
		$this->link->query("SET SQL_MODE = ''");
	}

	public function query($sql) {
		$query = $this->link->query($sql);

		if (!$this->link->errno){
			if (isset($query->num_rows)) {
				$data = array();

				while ($row = $query->fetch_assoc()) {
					$data[] = $row;
				}

				$result = new stdClass();
				$result->num_rows = $query->num_rows;
				$result->row = isset($data[0]) ? $data[0] : array();
				$result->rows = $data;

				unset($data);

				$query->close();

				return $result;
			} else{
				return true;
			}
		} else {
			throw new ErrorException('Error: ' . $this->link->error . '<br />Error No: ' . $this->link->errno . '<br />' . $sql);
			exit();
		}
	}

	public function escape($value) {
		return $this->link->real_escape_string($value);
	}

	public function countAffected() {
		return $this->link->affected_rows;
	}

	public function getLastId() {
		return $this->link->insert_id;
	}

	public function __destruct() {
		$this->link->close();
	}
}
?>
-----------------------------
the second one is seemengly still called mysql, but it contains mysqli - routines:
mysql.php
define('DB_DRIVER', 'mysql');
-----------------------------

Code: Select all

<?php
    final class MySQL {
        private $link;

        public function __construct($hostname, $username, $password, $database) {

            $this->link = @new mysqli($hostname, $username, $password, $database);

            if (mysqli_connect_error()) {
                trigger_error('Error: Could not connect to database "' . $database . '"', E_USER_WARNING);
                die;
            }

            $this->link->set_charset('utf8');
            $this->link->query("SET SQL_MODE = ''");
        }

        public function query($sql) {

            $resource = $this->link->query($sql);

            if ($this->link->errno) {
                trigger_error('Error: ' . $this->link->error . '<br />Error No: ' . $this->link->errno . '<br />' . $sql);
                die;
            }

            if ($resource instanceof mysqli_result) {
                $i = 0;

                $data = array();

                while ($result = $resource->fetch_assoc()) {
                    $data[$i] = $result;

                    $i++;
                }

                $resource->free();

                $query = new stdClass();
                $query->row = isset($data[0]) ? $data[0] : array();
                $query->rows = $data;
                $query->num_rows = $i;

                unset($data);

                return $query;
            }

            return $resource;
        }

        public function escape($value) {

            return $this->link->real_escape_string($value);
        }

        public function countAffected() {

            return $this->link->affected_rows;
        }

        public function getLastId() {

            return $this->link->insert_id;
        }

        public function __destruct() {

            if (!mysqli_connect_error()) {
                $this->link->close();
            }
        }
    }
?>
--------------------------------
or then, change your BOTH config.php files to: mysqliz, and use this one below:
define('DB_DRIVER', 'mysqliz');
--------------------------------

Code: Select all

<?php
final class MySQLiz {
	private $mysqli_handler;
	
	public function __construct($hostname, $username, $password, $database) {
		$this->mysqli_handler = new mysqli($hostname, $username, $password, $database);
		
		if ($this->mysqli_handler->connect_error) {
      		trigger_error('Error: Could not make a database link (' . $this->mysqli_handler->connect_errno . ') ' . $this->mysqli_handler->connect_error);
		}
		
		$this->mysqli_handler->query("SET NAMES 'utf8'");
		$this->mysqli_handler->query("SET CHARACTER SET utf8");
		$this->mysqli_handler->query("SET CHARACTER_SET_CONNECTION=utf8");
		$this->mysqli_handler->query("SET SQL_MODE = ''");
  }
		
  public function query($sql) {
		$result = $this->mysqli_handler->query($sql, MYSQLI_STORE_RESULT);
		if ($result !== FALSE) {
			if (is_object($result)) {
				$i = 0;
    	
				$data = array();
		
				while ($row = $result->fetch_array(MYSQLI_ASSOC)) {
					$data[$i] = $row;
    	
					$i++;
				}

				$result->close();
				
				$query = new stdClass();
				$query->row = isset($data[0]) ? $data[0] : array();
				$query->rows = $data;
				$query->num_rows = count($data);
				unset($data);
				return $query;
			
			}
			else {
				return true;
			}
		}
		else {
			trigger_error('Error: ' . $this->mysqli_handler->error . '<br />Error No: ' . $this->mysqli_handler->errno . '<br />' . $sql);
			exit();
		}
  }
	
	public function escape($value) {
		return $this->mysqli_handler->real_escape_string($value);
	}
	
	public function countAffected() {
		return $this->mysqli_handler->affected_rows;
	}

	public function getLastId() {
		return $this->mysqli_handler->insert_id;
	}	
	
	public function __destruct() {
		$this->mysqli_handler->close();
	}
}
?>
----------------------------
and this is a mysqli.php by famous MaxD, created for an OC 1.5.6. parser
define('DB_DRIVER', 'mysqli');
----------------------------

Code: Select all

<?php
final class MySQLi {
	private $mysqli;
	
	public function __construct($hostname, $username, $password, $database) {
		$this->mysqli = new mysqli($hostname, $username, $password, $database);
		
		if ($this->mysqli->connect_error) {
      		trigger_error('Error: Could not make a database link (' . $this->mysqli->connect_errno . ') ' . $this->mysqli->connect_error);
		}
		
		$this->mysqli->query("SET NAMES 'utf8'");
		$this->mysqli->query("SET CHARACTER SET utf8");
		$this->mysqli->query("SET CHARACTER_SET_CONNECTION=utf8");
		$this->mysqli->query("SET SQL_MODE = ''");
  	}
		
  	public function query($sql) {
		$result = $this->mysqli->query($sql);

		

		if ($this->mysqli->errno) {
		//$mysqli->errno
		}
		
			if (is_resource($resource)) {
				$i = 0;
    	
				$data = array();
		
				while ($row = $result->fetch_object()) {
					$data[$i] = $row;
    	
					$i++;
				}

				$result->close();
				
				$query = new stdClass();
				$query->row = isset($data[0]) ? $data[0] : array();
				$query->rows = $data;
				$query->num_rows = $result->num_rows;
				
				unset($data);
				
				
				
				
				return $query;	
    		} else {
				return true;
			}
		} else {
			trigger_error('Error: ' . mysql_error($this->link) . '<br />Error No: ' . mysql_errno($this->link) . '<br />' . $sql);
			exit();
    	}
  	}
	
	public function escape($value) {
		return $this->mysqli->real_escape_string($value);
	}
	
  	public function countAffected() {
    	return $this->mysqli->affected_rows;
  	}

  	public function getLastId() {
    	return $this->mysqli->insert_id;
  	}	
	
	public function __destruct() {
		$this->mysqli->close();
	}
}
?>
Good Luck ;)
Ernie
openshop.li

Please don't send me OC Forum Personal Messages, just contact: jti@jacob.ch
---
OC 1.5.6.5 LIGHT Test Site: http://www.bigmax.ch/shop/
OC 1.5.6.5 V-PRO Test Site: http://www.openshop.li/shop/
My Github OC Site: https://github.com/IP-CAM
2'800+ FREE OC Extensions on the World's largest Github OC Repository Archive Site.


User avatar
Legendary Member

Posts

Joined
Tue Mar 04, 2014 1:37 am
Location - Switzerland

Post by ocart777 » Mon Feb 29, 2016 3:40 am

knight_47 wrote:I really appreciate your help here. I'm a little confused here, is that code suppose to replace the whole /systems/database/mysqli.php file? I just replaced your code with my mysqli.php code, and it came up with additional errors.

Any other ideas?
in your mysqli.php file, replace all from line 18 to 58 with my posted code above

You can't control the weather, but you can change your mood.
You can't modify the visage, but you can show your smile.
You can't command someone else, but you can hold yourself.
You can't forecast tomorrow, but you can using today.
You can't obtain thanks, but you can exert yourself in everything.


OCEXTENSION.COM - YOUR PROFESSIONAL OPENCART EXTENSION STORE


User avatar
Active Member

Posts

Joined
Mon Jun 10, 2013 4:57 pm
Location - Malaysia
Who is online

Users browsing this forum: No registered users and 30 guests