Home >Backend Development >PHP Problem >How to implement raw transmission database in php
php method to implement raw transmission database: 1. Create a PHP sample file; 2. Use CURL to send postman’s raw format data, with code such as “curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);curl_setopt( $ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json')".
The operating environment of this tutorial: windows7 system, PHP version 8.1, Dell G3 computer.
How does PHP implement raw transmission to the database?
PHP uses CURL to send postman’s raw format data
I have been using What is sent directly is a string in a single format. When connecting to the external site data today, they require an object format string, which is the raw format data in postman.
$data = "{ name: 'job', age: 20, hobby: [ { before: 'Play games', now: 'read book' } ] }"; $ch = curl_init(); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Content-Type: application/json' ) ); $response = curl_exec($ch); $response = json_decode($response);
It is worth noting that The header must have `'Content-Type: application/json'. Without the type, the receiving end will not be able to parse.
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of How to implement raw transmission database in php. For more information, please follow other related articles on the PHP Chinese website!