OC version 1.5.6.4.
I have upgraded to mqsqli and everything but a contribution is working.
It has a line in it like:
$cat = trim(mysql_real_escape_string($product['cname']) );
Since I have moved to mysqli I figured it would be as simple as changing mysql to mysqli on that line BUT when I change that and run the script it errors out with mysqli_real_escape_string() expects exactly 2 parameters, 1 given...
Searching online I see mysqli requires a link to the database. An example is:
$city = mysqli_real_escape_string($link, $city);
Where $link is declared above that line like:
$link = mysqli_connect("localhost", "my_user", "my_password", "world");
SOOOOOOOO since the contrib has this above in it:
$db = new DB(DB_DRIVER, DB_HOSTNAME, DB_USERNAME, DB_PASSWORD, DB_DATABASE);
I thought I should be able to then further change that line above to
$cat = trim(mysqli_real_escape_string($db,($product['cname'])) );
But it doesn't work. Am I close or am I really missing something?
Thank you,
Mike
I have upgraded to mqsqli and everything but a contribution is working.
It has a line in it like:
$cat = trim(mysql_real_escape_string($product['cname']) );
Since I have moved to mysqli I figured it would be as simple as changing mysql to mysqli on that line BUT when I change that and run the script it errors out with mysqli_real_escape_string() expects exactly 2 parameters, 1 given...
Searching online I see mysqli requires a link to the database. An example is:
$city = mysqli_real_escape_string($link, $city);
Where $link is declared above that line like:
$link = mysqli_connect("localhost", "my_user", "my_password", "world");
SOOOOOOOO since the contrib has this above in it:
$db = new DB(DB_DRIVER, DB_HOSTNAME, DB_USERNAME, DB_PASSWORD, DB_DATABASE);
I thought I should be able to then further change that line above to
$cat = trim(mysqli_real_escape_string($db,($product['cname'])) );
But it doesn't work. Am I close or am I really missing something?
Thank you,
Mike
cue4cheap not cheap quality
Cue4cheap wrote:OC version 1.5.6.4.
I have upgraded to mqsqli and everything but a contribution is working.
It has a line in it like:
$cat = trim(mysql_real_escape_string($product['cname']) );
Since I have moved to mysqli I figured it would be as simple as changing mysql to mysqli on that line BUT when I change that and run the script it errors out with mysqli_real_escape_string() expects exactly 2 parameters, 1 given...
Searching online I see mysqli requires a link to the database. An example is:
$city = mysqli_real_escape_string($link, $city);
Where $link is declared above that line like:
$link = mysqli_connect("localhost", "my_user", "my_password", "world");
SOOOOOOOO since the contrib has this above in it:
$db = new DB(DB_DRIVER, DB_HOSTNAME, DB_USERNAME, DB_PASSWORD, DB_DATABASE);
I thought I should be able to then further change that line above to
$cat = trim(mysqli_real_escape_string($db,($product['cname'])) );
But it doesn't work. Am I close or am I really missing something?
Thank you,
Mike
Well I resolved it by doing exactly that: I created
$link = mysqli_connect(DB_HOSTNAME, DB_USERNAME, DB_PASSWORD, DB_DATABASE);
and put it under:
$db = new DB(DB_DRIVER, DB_HOSTNAME, DB_USERNAME, DB_PASSWORD, DB_DATABASE);
and changed the line to:
$cat = trim(mysqli_real_escape_string($link,($product['cname'])) );
It works BUT I would love to know the best way and IF I can use the original $db variable like
$cat = trim(mysqli_real_escape_string($db,($product['cname'])) );
instead of creating the other variable: $link = mysqli_connect(DB_HOSTNAME, DB_USERNAME, DB_PASSWORD, DB_DATABASE);
Thank you,
Mike
cue4cheap not cheap quality
Could someone explain the $db = new DB(DB_DRIVER, DB_HOSTNAME, DB_USERNAME, DB_PASSWORD, DB_DATABASE); line to me and why it doesn't work the same as $link = mysqli_connect(DB_HOSTNAME, DB_USERNAME, DB_PASSWORD, DB_DATABASE);?Cue4cheap wrote: and put it under:
$db = new DB(DB_DRIVER, DB_HOSTNAME, DB_USERNAME, DB_PASSWORD, DB_DATABASE);
and changed the line to:
$cat = trim(mysqli_real_escape_string($link,($product['cname'])) );
It works BUT I would love to know the best way and IF I can use the original $db variable like
$cat = trim(mysqli_real_escape_string($db,($product['cname'])) );
instead of creating the other variable: $link = mysqli_connect(DB_HOSTNAME, DB_USERNAME, DB_PASSWORD, DB_DATABASE);
Thank you,
Mike
It may be a novice PHP question but that is what I am.

Mike
cue4cheap not cheap quality
$db is an instantiation of the Opencart db class
$link is plain old procedural using the php mysql function
try $cat = $this->db->escape($product['cname']); (Shouldn't work in the tpl when using OC2)
I wonder why people don't use the framework, it's bound to break stuff
Basically in MVC PHP those php functions are wrapped in a class for convenience
$link is plain old procedural using the php mysql function
try $cat = $this->db->escape($product['cname']); (Shouldn't work in the tpl when using OC2)
I wonder why people don't use the framework, it's bound to break stuff

Basically in MVC PHP those php functions are wrapped in a class for convenience
Attn: I no longer provide OpenCart extensions, nor future support - this includes forum posts.
Reason: OpenCart version 3+
Thanks!
I see the two are basically the same but I guess I need to do more reading because I'll have to say it is still over my head.artcore wrote:$db is an instantiation of the Opencart db class
$link is plain old procedural using the php mysql function
try $cat = $this->db->escape($product['cname']); (Shouldn't work in the tpl when using OC2)
I wonder why people don't use the framework, it's bound to break stuff![]()
Basically in MVC PHP those php functions are wrapped in a class for convenience
Thank you for the reply.
cue4cheap not cheap quality
Who is online
Users browsing this forum: No registered users and 4 guests