I am not new to coding php but I am new to using the Appgini php functions. With that said I would love to see how you guys would rewrite this code using the Appgini php functions. This is the best way for me to learn
Code: Select all
<?php
include('../lib.php');
//$pid = $_POST['pid'];
$pid = "1";
$db_host = config('dbServer');
$db_user = config('dbUsername');
$db_pwd = config('dbPassword');
$db_dbase = config('dbDatabase');
//$link = db_connect([$db_host], [$db_user], [$db_pwd], [$db_dbase]);
$link = mysqli_connect($db_host, $db_user, $db_pwd, $db_dbase);
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$query = "SELECT id, inspection_type, fld_1, fld_2, fld_3, fld_4, fld_5, fld_6, fld_7, fld_8, fld_9, fld_10, fld_11, fld_12, fld_13, fld_14, fld_15, fld_16, fld_17, fld_18, fld_19, fld_20, fld_21, fld_22, fld_23, fld_24, fld_25 FROM inspection_setup WHERE inspection_type=?";
/* create a prepared statement */
$stmt = mysqli_stmt_init($link);
mysqli_stmt_prepare($stmt,$query);
/* bind parameters for markers */
mysqli_stmt_bind_param($stmt, "s", $pid);
/* execute query */
mysqli_stmt_execute($stmt);
/* bind result variables */
mysqli_stmt_bind_result($stmt,$id,$inspection_type,$fld_1,$fld_2,$fld_3,$fld_4,$fld_5,$fld_6,$fld_7,$fld_8,$fld_9,$fld_10,$fld_11,$fld_12,$fld_13,$fld_14,$fld_15,$fld_16,$fld_17,$fld_18,$fld_19,$fld_20,$fld_21,$fld_22,$fld_23,$fld_24,$fld_25);
/* fetch value */
mysqli_stmt_fetch($stmt);
/* concatenate results */
$results = "";
for ($x=1;$x<=25;$x++){
$results = $results.${"fld_".$x}.',';
}
echo $results;
/* close statement */
mysqli_stmt_close($stmt);
?>