$wpdb – MySQL result set – vs PDO
-
Hi. I’m working on a plugin which will access data from existing tables (imported into the existing WordPress db from a Drupal db (not an external db)). The SQL uses aliases and seemed to be difficult to get to the data using mysqli. I was advised to use PDO, and I was able to successfully query MySQL to get the data result set I wanted (link to img). Here’s what I have for that:
function getUsers($conn) { $pdoConn = $conn->prepare("SELECT DISTINCT Nmbr.uid as Nmbr_uid, Nmbr.fid as Nmbr_fid, Nmbr.value as Nmbr_value, Name.fid as Name_fid, Name.value as Name_value, u.uid as u_uid, u.status as u_status, Name.uid as Name_uid FROM profile_values Nmbr INNER JOIN users u ON u.uid = Nmbr.uid INNER JOIN profile_values Name ON Name.uid = u.uid WHERE Name.fid = 1 AND Nmbr.fid = 11 AND Nmbr.value != '' AND (Name.value!='Retiree' OR Nmbr.value = '1') ORDER BY Name.value DESC"); $name_val = $pdoConn->bindValue(":Name_value", 32); $nmbr_val = $pdoConn->bindValue(":Nmbr_value", 10); $tryPrint = array(); $pdoConn->execute(); while ($row = $pdoConn->fetch(PDO::FETCH_ASSOC)) { $tryPrint[] = $row; } foreach ($tryPrint as $try_row => $try_val) { print "Row $try_row: <br>"; print "Name: " . $try_val['Name_value'] . "<br>"; print "Nmbr: " . $try_val['Nmbr_value'] . "<br>"; print "<br>"; } }
I would prefer to use $wpdb , but I have been trying various permutations of code with no success on this query. Please advise.
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘$wpdb – MySQL result set – vs PDO’ is closed to new replies.