Minggu, 13 Februari 2022

getData baru

 

terkadang sudah di hosting dan sudah diubah2 versi xampp online dar 5.4 sd 7.4 masih tidak muncul datanya padahal login,hapus, simpan, ubah data satuan bisa....maka gunakan  fungsi getData sbb:





 function getData($conn,$sql){

$ar=array();

if($result = mysqli_query($conn, $sql)){

if(mysqli_num_rows($result) > 0){

while($row = mysqli_fetch_array($result)){

  $ar[] =$row;

}

mysqli_free_result($result);

//mysqli_close($conn);

return $ar;

}



function getDatab($conn,$sql){

$result = $conn->query($sql);

$outp = array(); 

if ($result->num_rows > 0) { 

  while($row = $result->fetch_assoc()) {

    //echo "id: " . $row["id"]. " - Name: " . $row["firstname"]. " " . $row["lastname"]. "<br>";

$outp[]=$row;

  }

}  

//$conn->close();

return $outp;

}


yang lama


<?php

function process($conn,$sql){

$s=false;

$conn->autocommit(FALSE);

try {

  $rs = $conn->query($sql);

  if($rs){

    $conn->commit();

    $last_inserted_id = $conn->insert_id;

  $affected_rows = $conn->affected_rows;

  $s=true;

  }

catch (Exception $e) {

echo 'fail: ' . $e->getMessage();

  $conn->rollback();

}

$conn->autocommit(TRUE);

return $s;

}


function getJum($conn,$sql){

  $rs=$conn->query($sql);

  $jum= $rs->num_rows;

$rs->free();

return $jum;

}


function getField($conn,$sql){

$rs=$conn->query($sql);

$rs->data_seek(0);

$d= $rs->fetch_assoc();

$rs->free();

return $d;

}


$outp = array();    


 

function getData($conn,$sql){

/*

$rs=$conn->query($sql);

$rs->data_seek(0);

$arr = $rs->fetch_all(MYSQLI_ASSOC);

//foreach($arr as $row) {

//  echo $row['nama_kelas'] . '*<br>';

//}

$rs->free();

*/

$result = $conn->query($sql);

$outp = array();    


while ($row = $result->fetch_array(MYSQLI_ASSOC)) {

    $outp[] = $result->fetch_array(MYSQLI_ASSOC);

}


return $outp;

}

function getData2($conn,$sql){

$rs=$conn->query($sql);

$rs->data_seek(0);

$arr = $rs->fetch_all(MYSQLI_ASSOC);

//foreach($arr as $row) {

//  echo $row['nama_kelas'] . '*<br>';

//}

$rs->free();

return $arr;

}


function getAdmin($conn,$kode){

$field="nama_admin";

$sql="SELECT `$field` FROM `tb_admin` where `id_admin`='$kode'";

$rs=$conn->query($sql);

$rs->data_seek(0);

$row = $rs->fetch_assoc();

$rs->free();

    return $row[$field];

}

function getRM($conn,$kode){

$field="nama_ibuhamil";

$sql="SELECT `$field` FROM `tb_ibuhamil` where `id_rm`='$kode'";

$rs=$conn->query($sql);

$rs->data_seek(0);

$row = $rs->fetch_assoc();

$rs->free();

    return $row[$field];

}

function getID($conn,$kode){

$field="nama_ibuhamil";

$sql="SELECT `$field` FROM `tb_ibuhamil` where `id`='$kode'";

$rs=$conn->query($sql);

$rs->data_seek(0);

$row = $rs->fetch_assoc();

$rs->free();

    return $row[$field];

}

?>


Auto ENter:

$keterangan=$d["keterangan"];

$keterangan = wordwrap($keterangan, 20, "<br />"); 













Tidak ada komentar:

Posting Komentar

Selisih Waktu Berjalan

Berikut adalah fungsi PHP yang menghitung selisih hari antara tanggal saat ini dengan tanggal 2024-08-22 . Jika tanggal saat ini kurang dari...