how to make an array data from database before transfer using curl php -


i want ask array in php.

i have build curl php , transferring data. problem want transfer using array.

this code:

<?php   $sql = "select domain_name  domain";    $result = mysqli_query($conn, $sql);   if (mysqli_num_rows($result) > 0)    {     while($row = mysqli_fetch_assoc($result))      {        $domain= $row['domain_name'];       $content= $row['domain_content']; // values row-wise db       $reason = $row['reason'];        $curlhandle = curl_init();       curl_setopt($curlhandle, curlopt_url, '192.168.100.2/update.php');       curl_setopt($curlhandle, curlopt_post, 1);       curl_setopt($curlhandle, curlopt_header, 0);       curl_setopt($curlhandle, curlopt_ssl_verifypeer, 0);       curl_setopt($curlhandle, curlopt_postfields, 'domain_name='.$domain.);       curl_setopt($curlhandle, curlopt_followlocation,1);        curl_setopt($curlhandle, curlopt_returntransfer,1);        if (!curl_exec($curlhandle))        {         //echo 'everything successful';       }       else        {         echo 'an error has occurred: ' . curl_error($curlhandle);       }       } /* end of while loop */    } /* end of num rows result more 0 */   else    {     echo "0 results";   } ?> 

from code above, system running in loop when sending data until data database transferred.

you can create array

$curl_array = [   'domain' => $row['domain_name'],   'content' => $row['domain_content'],   'reason' => $row['reason'] ]; 

if php older 5.4 this

$curl_array = array(   'domain' => $row['domain_name'],   'content' => $row['domain_content'],   'reason' => $row['reason'] ); 

you can read arrays @ http://php.net/manual/en/language.types.array.php

also suggest json encoding (json_encode()) data before send updating curl_setopt

curl_setopt($curlhandle, curlopt_postfields, 'data='.json_encode($curl_array).); 

note have update script 192.168.100.2/update.php account array , json_decode()

eg:

$curl_post = json_decode($_post['data']); $domain => $curl_post['domain_name']; $content => $curl_post['domain_content']; $reason => $curl_post['reason']; 

full code:

  <?php     $sql = "select domain_name  domain";      $result = mysqli_query($conn, $sql);     if (mysqli_num_rows($result) > 0)      {     while($row = mysqli_fetch_assoc($result))       {      // values db ans populate array     $curl_array = [       'domain' => $row['domain_name'],       'content' => $row['domain_content'],       'reason' => $row['reason']     ];      $curlhandle = curl_init();     curl_setopt($curlhandle, curlopt_url, '192.168.100.2/update.php');     curl_setopt($curlhandle, curlopt_post, 1);     curl_setopt($curlhandle, curlopt_header, 0);     curl_setopt($curlhandle, curlopt_ssl_verifypeer, 0);     curl_setopt($curlhandle, curlopt_postfields, 'data='.json_encode($curl_array).);     curl_setopt($curlhandle, curlopt_followlocation,1);      curl_setopt($curlhandle, curlopt_returntransfer,1);        if (!curl_exec($curlhandle))      {     //echo 'everything successful';     }     else      {     echo 'an error has occurred: ' . curl_error($curlhandle);     }      }     }       else      {     echo "0 results";     }   ?> 

Comments

Popular posts from this blog

javascript - Bootstrap Popover: iOS Safari strange behaviour -

Magento/PHP - Get phones on all members in a customer group -

session - Logging Out Using PHP -