Last active
April 27, 2016 14:39
-
-
Save xavbeta/bebeba41368b7392c85ed06a7638a058 to your computer and use it in GitHub Desktop.
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 | |
DEFINE("DB_ADDRESS", "localhost"); | |
DEFINE("DB_NAME", "#####"); | |
DEFINE("DB_USER", "#####"); | |
DEFINE("DB_PASSWORD", "#####"); | |
function openConnection(){ | |
// Create connection | |
$conn = new mysqli(DB_ADDRESS, DB_USER, DB_PASSWORD, DB_NAME); | |
// Check connection | |
if ($conn->connect_error) { | |
die("Connection failed: " . $conn->connect_error); | |
} | |
echo "Connected successfully\n"; | |
return $conn; | |
} | |
function closeConnection($conn){ | |
$conn->close(); | |
} | |
function saveMessage($conn, $message) { | |
$conn->query("INSERT INTO message (id, payload) VALUES (NULL, '$message')") | |
or die(mysqli_error($conn)); | |
} | |
function getMessageCount($conn) { | |
$count = 0; | |
if($result = $conn->query("SELECT COUNT(*) as count FROM message")) { | |
$array_result = $result->fetch_assoc(); | |
printf("Totale messaggi: %d\n", $array_result['count']); | |
$count = $array_result['count']; | |
} | |
$result->close(); | |
return $count; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment