<?php

  require '../conf/config.php';

  //////////////////////////////////  Connecting with DB
  if( !$conn = new mysqli($host, $user, $pswd, $db)) {
    error_log("Connection failed.\n");
    exit;
  }

  ////////////////////////////////////////////////////////// Chromosome
  $chr = array();
  $size = array();
  $centomeres = array();
  
  $query = "SELECT id,size,centromere_s+(centromere_e-centromere_s)/2 FROM sys_chromosome order by seq";
  $stmt = $conn->stmt_init();
  $stmt->prepare($query);
  $stmt->execute();
  //$stmt->store_result();
  $stmt->bind_result($row0,$row1,$row2);
  while ($stmt->fetch()) {
	$chr[]=$row0;
    $size[]=$row1;
    $centromeres[]=(int)$row2;
  }
  //$stmt->free_result();
  $stmt->close();
  mysqli_close($conn);
  
  $str="[";
  for ($i=0; $i<count($chr); $i++) {
    $str=$str."{\"id\":\"".$chr[$i]."\",\"size\":\"".$size[$i]."\",\"centromere\":\"".$centromeres[$i]."\"}"; 
    if($i<count($chr)-1) $str=$str.",";
  }
  $str=$str."]";

  echo $str;

?>

