Skip to content

Instantly share code, notes, and snippets.

@siteslave
Created December 16, 2013 04:13
Show Gist options
  • Select an option

  • Save siteslave/7982179 to your computer and use it in GitHub Desktop.

Select an option

Save siteslave/7982179 to your computer and use it in GitHub Desktop.
[ประกอบหนังสือ Bootstrap]
<?php
$dsn = 'mysql:host=localhost; dbname=test';
$username = 'root';
$password = '';
try {
$conn = new PDO( $dsn, $username, $password);
$conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
} catch ( PDOException $e ) {
echo 'Connection failed: ' . $e->getMessage();
}
$callback = $_GET['callback'];
$sql_total = 'select count(*) as total from hospitals';
$st = $conn->prepare($sql_total);
$st->execute();
$rows_total = $st->fetch();
$json = '{"ok": 1, "total": ' . $rows_total['total'] . '}';
echo $callback . '(' . $json . ')';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment