Skip to content

Instantly share code, notes, and snippets.

@linkarys
Created March 30, 2013 05:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save linkarys/5275507 to your computer and use it in GitHub Desktop.
Save linkarys/5275507 to your computer and use it in GitHub Desktop.
php: connect mysql
<?php
// Create connection
$con=mysqli_connect("localhost","root","Kit to 0","sunshine");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
} else {
$sql = "SELECT date, sum(total) AS spend
FROM comsumption
GROUP BY date
ORDER BY date";
$result = mysqli_query($con, $sql);
// echo $result;
// echo 'data,'.'spend'.'\r\n';
$i = 0;
while($row = mysqli_fetch_array($result)) {
$arr_result[$i++] = array($row['date'], $row['spend']);
// print_r($row);
// echo $row[0] . ',' . $row[1] . '\r\n';
// echo $row['date'] . ", " . $row['spend'];
// echo "<br />";
}
echo json_encode($arr_result);
// print_r($arr_result);
print_r($_SESSION);
mysqli_close($con);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment