How to implement raw transmission database in php

藏色散人
Release: 2023-03-17 09:58:02
Original
1475 people have browsed it

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')".

How to implement raw transmission database in php

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);
Copy after login

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!

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!