I am using a nice piece of code to reorder db content using drag and drop. I can get it to work locally by enabling the PDO extension in the php.ini file but my hosting package (shared) does not allow PDO and MySQLi simultaneously. I am unfamiliar with PDO and I would appreciate any help in rewriting the following segment to work with MySQLi, if possible.
Thanks.
<?php
if (isset($_POST['orders'])) {
} else {
echo json_encode(array('error' => true));
}
$orders = explode('&', $_POST['orders']);
$array = array();
foreach($orders as $item) {
$item = explode('=', $item);
$item = explode('_', $item[1]);
$array[] = $item[1];
}
try {
$objDb = new PDO('mysql:host=localhost;dbname=test', 'user', 'pw');
$objDb->exec("SET CHARACTER SET utf8");
foreach($array as $key => $value) {
$key = $key + 1;
$sql = "UPDATE `artwork`
SET `listorder` = ?
WHERE `id` = ?";
echo $sql;
$objDb->prepare($sql)->execute(array($key, $value));
}
echo json_encode(array('error' => false));
} catch(Exception $e) {
echo json_encode(array('error' => true));
}
My recommendation? Find another host. Going from PDO to mysqli is not a good idea, because you will waste time porting code into a less portable state.
— Edit —
You can try the following code snippet, if it doesn’t work it should get you started. I couldn’t test it because none of my servers have mysql* modules compiled.
You can get more information on mysqli query and other functions here.
Anyway, good luck.