我有一个web服务启动并运行,但我只能从我的数据库读取数据。如何编写php代码更新web服务
任何人都可以帮助/指导我如何将PHP文件编码成能够写入我的数据库?
// Create connection
$con=mysqli_connect("server_address","database_name","user_name","table_name");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
// This SQL statement selects ALL from the table ’table_name’
$sql = "SELECT * FROM table_name/";
// Check if there are results
if ($result = mysqli_query($con, $sql))
{
// If so, then create a results array and a temporary one
// to hold the data
$resultArray = array();
$tempArray = array();
// Loop through each row in the result set
while($row = $result->fetch_object())
{
// Add each row into our results array
$tempArray = $row;
array_push($resultArray, $tempArray);
}
// Finally, encode the array to JSON and output the results
echo json_encode($resultArray);
}
// Close connections
mysqli_close($result);
mysqli_close($con);
?>
+3
http://dev.mysql.com/doc/refman/5.6/en/insert.html –