<?php $server = "localhost"; // host server $username= "root"; // username $password = ""; // password $connect = mysql_connect($server, $username, $password); if ( !$connect ) { die("connect thanh cong"); } else { // connect success // chon database mysql_select_db("ten database",$db) or die("Khong the select database!"); //truy van $sql = "select * from `tablename`"; $result = mysql_query($sql); // lay ket qua $data = array(); while($row = mysql_fetch_assoc($result)){ $data[] = $row; } // xuat ra json echo json_encode($data); //xem thu ket qua truy van echo '<pre>'; print_r($data); echo '</pre>'; } mysql_close($connect); ?>