<?php header("Content-Type: application/json; charset=utf-8"); require '../config/mysql2json.php'; require '../config/config.php'; function makeSQL() { $request = 'select * from stockprice_brand'; if (s($_GET["q"]) != "") { $request .= sprintf(" where company_name like '%s' or company_name_kana like '%s'", s($_GET["q"]), s($_GET["q"])); } $request .= " limit 5;"; return $request; } $link = mysql_connect($db_host, $db_username, $db_password) or die(mysql_error()); $db_select = mysql_select_db($db_database) or die(mysql_error()); $query = makeSQL(); $res = mysql_query($query); if (!is_string($res)) { $num = mysql_affected_rows($link); $objJSON = new mysql2json(); echo $_GET['callback'] . "(" . trim($objJSON->getJSON($res, $num)) . ")"; } else { echo $_GET['callback'] . "(" . json_encode(array('status' => 'ERROR', 'error' => 'failed')) . ")"; } mysql_close($link); exit;
<?php include 'mysql2json.class.php'; include 'connect.php'; ?> <?php header('Content-type: application/json; charset=utf-8'); header('Access-Control-Allow-Origin: *'); $num = 0; $sql = 'select id,student_id,initname,firstname,lastname,middlename from member'; $result = mysql_query($sql) or die(mysql_error()); $num = mysql_affected_rows(); $objJSON = new mysql2json(); print trim($objJSON->getJSON($result, $num)); ?>
$hostname_connection = "localhost"; $database_connection = "thailand"; $username_connection = "root"; $password_connection = "l[kpfu"; $connection = mysql_connect($hostname_connection, $username_connection, $password_connection) or trigger_error(mysql_error(), E_USER_ERROR); mysql_query("SET character_set_results=utf8"); mysql_query("SET character_set_client=utf8"); mysql_query("SET character_set_connection=utf8"); mysql_select_db($database_connection, $connection); $ID = $_GET[ID]; $type = $_GET[TYPE]; if ($type == 'Proviance') { $query = "SELECT PROVINCE_ID, PROVINCE_NAME FROM province ORDER BY PROVINCE_NAME ASC "; } else { if ($type == 'District') { $query = "SELECT AMPHUR_ID, AMPHUR_NAME FROM amphur WHERE PROVINCE_ID='" . $ID . "'"; } else { if ($type == 'Subdistrict') { $query = "SELECT DISTRICT_ID, DISTRICT_NAME FROM district WHERE AMPHUR_ID='" . $ID . "'"; } else { if ($type == 'Postcode') { $query = "SELECT POST_CODE FROM amphur_postcode WHERE AMPHUR_ID='" . $ID . "'"; } } } } $result = mysql_query($query, $connection); $num = mysql_affected_rows(); $json = new mysql2json(); $data = $json->getJSON($result, $num); echo $data;