Welcome Guest, Not a member yet? Register   Sign In
Codeigniter with and on duplicate key
#1

[eluser]epseix[/eluser]
Looking for a bit of advice.

I have an update script for my website's database, but as yet - I've not been able to figure out how to convert it to the Codeigniter framework ie. it's saved as it's own file in the home directory of my website, and executed from there.

There's a couple of things making it difficult for me to figure out: 1. It uses php xpath - not difficult to see how I would convert this to a Codeigniter controller, but I'm wondering if update_batch would be a better solution for me as opposed to using a foreach loop as each row is update by just 1 index column. There's next to no documentation available on this however...

2. My code utilises MySql's On duplicate feature which as I understand is not supported in Codeigniter.

Code:
$string = 'http://mywebsiteetc.com/xml/gzip/';
$xml    = simplexml_load_file("compress.zlib://$string");
foreach ($xml->xpath('//merchant') as $row)
{
                $merchant_id   = $row['id'];
                $merchant_name = $row['name'];
                mysqli_query($con, "INSERT INTO merchants (merchant_id, merchant_name) VALUES ('$merchant_id', '$merchant_name') ON DUPLICATE KEY UPDATE merchant_id = '$merchant_id', merchant_name = '$merchant_name'");
}

Can anyone steer me in the right direction as to how to implement the above into a controller/model environment - and of course, advise me of the most efficient way to do all of the above if there is one?

Cheers!




Theme © iAndrew 2016 - Forum software by © MyBB