<repo_name>TeacHKal/PHP---Scripts-for-Android-Chat-app<file_sep>/chat_app/index.php
<?php
echo "tannaan";<file_sep>/chat_app/chat.php
<?php
echo "lalal";<file_sep>/chat_app/upload.php
<?php
include 'credencials.php';

$db_driver = Credencials::db_driver;
$servername = Credencials::servername;
$dbname = Credencials::dbname;
$port = Credencials::port;
$username = Credencials::username;
$password = Credencials::password;

// $json = file_get_contents ( $_POST['data1'] );
$obj = json_decode ( $_POST ['json'] );
$nickname = $obj->{'nickname'};
$message = $obj->{'message'};

try {
	$conn = new PDO ( "mysql:host=$servername;dbname=$dbname", $username, $password );
	// set the PDO error mode to exception
	$conn->setAttribute ( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
	
	// prepare sql and bind parameters
	$stmt = $conn->prepare ( "INSERT INTO chat_app (nickname, message) 
    VALUES (:nickname, :message)" );
	$stmt->bindParam ( ':nickname', $nickname );
	$stmt->bindParam ( ':message', $message );
	
	// insert a row
	// $nickname = "Bot1";
	// $message = "This is a bot message";
	$stmt->execute ();
	
	echo "New records created successfully";
} catch ( PDOException $e ) {
	echo "Error: " . $e->getMessage ();
}
$conn = null;
 
 <file_sep>/chat_app/.credencials.php
<?php

// Example of Credencials

class Credencials {
	const db_driver = "mysql";
	const servername = "";
	const dbname = "";
	const port = "";
	const username = "";
	const password = "";
}
<file_sep>/chat_app/download.php
<?php
include 'credencials.php';

$db_driver = Credencials::db_driver;
$servername = Credencials::servername;
$dbname = Credencials::dbname;
$port = Credencials::port;
$username = Credencials::username;
$password = Credencials::password;

try {
	$conn = new PDO ( "mysql:host=$servername;dbname=$dbname", $username, $password );
	// set the PDO error mode to exception
	$conn->setAttribute ( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
	$stmt = $conn->prepare ( "SELECT * FROM chat_app ORDER BY timestamp DESC LIMIT 30" );
	$stmt->execute ();
	$expression = $stmt->fetchAll ( \PDO::FETCH_ASSOC );
	$result = json_encode ( $expression );
	echo $result;
} catch ( PDOException $e ) {
	echo "Error: " . $e->getMessage ();
}
$conn = null;