Created
March 30, 2013 05:26
-
-
Save linkarys/5275507 to your computer and use it in GitHub Desktop.
php: connect mysql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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