Re-writing 3rd party addon to work with Phoenix

Open to all! Ask other shopowners for help.
Post Reply
LeeFoster
Contributor
Posts: 263
Joined: Sun Feb 28, 2021 9:41 pm
Phoenix Version: v1.0.8.20
Has thanked: 1 time
Been thanked: 5 times

Re-writing 3rd party addon to work with Phoenix

Post by LeeFoster »

Good morning Phoenix users.

I am currently modifying a 3rd party social media clone to fully work with Phoenix, currently works locally but not live, with that in mind I am creating this thread to ask questions where there is code that I am not sure how to convert to the Phoenix standard.

There are also some concerns over the fact the addon has it's own db connection that I would like to move away from, hence the code updates.

So here is my first issue, the below section of code puts a post into the db and returns the id to be used in later code.

Code: Select all

$query = mysqli_query($this->con, "INSERT INTO posts VALUES ('', '$body', '$added_by', '$user_to', '$date_added', 'no', 'no', '0', '$imageName')");

            $returned_id = mysqli_insert_id($this->con);
This is my progress so far, it puts the code into the db but does not return the id

Code: Select all

$query = tep_db_query("INSERT INTO posts VALUES ('', '$body', '$added_by', '$user_to', '$date_added', 'no', 'no', '0', '$imageName')");
            
            $returned_id = mysqli_insert_id($this->con);
I know $this->con needs to be changed but not sure what to.

Any help would be appreciated.


Join The Code Co-op to get access to your library in the Code Co-op Forum
ecartz
Core Team
Posts: 3084
Joined: Tue Nov 05, 2019 6:02 pm
Phoenix Version:
Has thanked: 4 times
Been thanked: 208 times

Re: Re-writing 3rd party addon to work with Phoenix

Post by ecartz »

LeeFoster wrote: Wed Apr 13, 2022 10:40 am

Code: Select all

$query = tep_db_query("INSERT INTO posts VALUES ('', '$body', '$added_by', '$user_to', '$date_added', 'no', 'no', '0', '$imageName')");
            
            $returned_id = mysqli_insert_id($this->con);
If you are using a recent version:

Code: Select all

$query = $db->query("INSERT INTO posts VALUES ('', '$body', '$added_by', '$user_to', '$date_added', 'no', 'no', '0', '$imageName')");
            
            $returned_id = mysqli_insert_id($db);
Note that the standard in Phoenix is to do the escaping just before submitting the query. If that code is escaping properly to avoid SQL injections, it is doing so outside the posted code.

It will take care of it for you if you use perform rather than query.

If this is inside a function, either do globals $db; first or use $GLOBALS['db'] instead.

You can find examples in the current code: https://github.com/CE-PhoenixCart/Phoen ... &type=code

If using an older version, use tep_db_insert_id() without specifying the connection and it will use the same one that query does.
LeeFoster
Contributor
Posts: 263
Joined: Sun Feb 28, 2021 9:41 pm
Phoenix Version: v1.0.8.20
Has thanked: 1 time
Been thanked: 5 times

Re: Re-writing 3rd party addon to work with Phoenix

Post by LeeFoster »

ecartz wrote: Wed Apr 13, 2022 11:14 am
LeeFoster wrote: Wed Apr 13, 2022 10:40 am

Code: Select all

$query = tep_db_query("INSERT INTO posts VALUES ('', '$body', '$added_by', '$user_to', '$date_added', 'no', 'no', '0', '$imageName')");
            
            $returned_id = mysqli_insert_id($this->con);
If you are using a recent version:

Code: Select all

$query = $db->query("INSERT INTO posts VALUES ('', '$body', '$added_by', '$user_to', '$date_added', 'no', 'no', '0', '$imageName')");
            
            $returned_id = mysqli_insert_id($db);
Note that the standard in Phoenix is to do the escaping just before submitting the query. If that code is escaping properly to avoid SQL injections, it is doing so outside the posted code.

It will take care of it for you if you use perform rather than query.

If this is inside a function, either do globals $db; first or use $GLOBALS['db'] instead.

You can find examples in the current code: https://github.com/CE-PhoenixCart/Phoen ... &type=code

If using an older version, use tep_db_insert_id() without specifying the connection and it will use the same one that query does.
version is 1.0.8.5

$GLOBALS['db'] seems to have fixed it. On to the next bit


Join The Code Co-op to get access to your library in the Code Co-op Forum
Post Reply