The php code is below
<?php
$it = 0;
$array_to_send = [[]];
function array_builder ($col1, $col2, $col3, $col4){
Global $it,$array_to_send;
$temp_array = [];
//echo $col1 . " " . $col2 . " " . $col3 . $col4;
array_push($temp_array,$col1);
array_push($temp_array,$col2);
array_push($temp_array,$col3);
array_push($temp_array,$col4);
//echo json_encode($temp_array);
$array_to_send = $temp_array;
//echo json_encode($array_to_send);
//$it += 1;
//echo $it;
return $array_to_send;
}
/*
$servername = $_GET["sn"];
$username = $_GET["un"];
$password = $_GET["pw"];
*/
$servername = "[REDACTED]";
$username = "[REDACTED]";
$password = "[REDACTED]";
try {
$conn = new PDO("mysql:host=$servername;dbname=[REDACTED]", $username, $password);
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
//echo "Connected successfully";
} catch(PDOException $e) {
echo "Connection failed: " . $e->getMessage();
}
try{
$select_all = $conn->prepare("SELECT * FROM bulk_sms_list;");
$select_all->execute();
$json_data = json_encode($select_all->fetchAll(PDO::FETCH_FUNC, "array_builder"));
$json_data = preg_replace("/\[\[/", "[[-", $json_data);
echo $json_data;
echo json_last_error_msg();
//echo print_r($select_all->fetchAll(PDO::FETCH_ASSOC));
//echo json_encode($select_all->fetchAll(PDO::FETCH_FUNC, "array_builder");
//echo print_r($array_to_send);
//echo json_encode($array_to_send);
}catch (PDOException $e){
echo $e;
}
The json that Is supposed to be outputted is here:
[["75","Data","Data","Data"],["76","Random_data","Random_data","Random_data"]]
As you can see with the preg replace on line 45 of the php file I have tried to replace [[ with [[- to make modx ignore the [[ but that doesn’t work. Currently nothing gets outputted because it thinks that data is a snippet. All help is appreciated.