My function to query database not working

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
iggabz
User
Posts: 85

My function to query database not working

Post by iggabz »

hello everyone. i have this same custom php function

function Details($doc_id) {
    $conn = db_connect("sample_db");
    if (!$conn) {
        die("Database connection failed: " . mysqli_connect_error());
    }
    $sql = "SELECT * FROM `view_tbl_kilos` WHERE doc_id = '$doc_id'";
    $qry = mysqli_query($conn, $sql);
    if (!$qry) {
        die("Query execution failed: " . mysqli_error($conn));
    }
    $row = mysqli_fetch_assoc($qry);
    mysqli_close($conn);
    if (!$row) {
        return null; 
    }
    return array(
        'alpha' => $row['alpha'],
        'bravo' => $row['bravo'],
        'delta' => $row['delta'],
        'charlie' => $row['charlie'],
        'echo' => $row['echo'],
        'foxtrot' => $row['foxtrot']
    );
}

i tried to use these lines in row_inserted to get the values of the array but it did not show.

$result = grsDetails($doc_id);
$alpha = $result['alpha'];
$bravo = $result['bravo'];
$charlie = $result['charlie'];
$delta = $result['delta'];
$echo = $result['echo'];
$foxtrot = $result['foxtrot'];

i have tested this and i have got data but in phpmaker it does not show. am i missing something?


arbei
User
Posts: 9389

Post by arbei »

  1. Your function name is "Details" but you called "grsDetails",
  2. There is no db_connect() unless you write that function yourself elsewhere,
  3. You better debug your code by, e.g. var_dump($conn, $sql, $qry, $row),
  4. If you write code in server events, it is much easier to use PHPMaker functions, e.g. $result = ExecuteRow($sql);, see Global Functions.

Post Reply