Yusuf
Yusuf

Reputation: 177

Getting mysql row using curl

Ok, so am trying to fetch mysql row from remote server database by posting 2 fields, member id and secret code

    if(isset($_GET['uid'])){
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "http://www.mysite.com/get_user_info/index.php");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_POST, true);
    $data = array(
        'member_id' => $_GET['uid'],
        'secret' => 'secret'
    );
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

    $output = curl_exec($ch);
    $info = curl_getinfo($ch);
    curl_close($ch);
}

on the remote server /get_user_info

i have this

    $query = mysql_query("SELECT * FROM user_data WHERE user_id = '$_POST[member_id]'");
    if($query){
        $row = mysql_fetch_row($query);
    }
print_r($row);

so am trying to fetch that user info row from mysql using curl, but i get just text

so how can i get usable php array, so i can do like <?php echo $output['name']; ?>

Upvotes: 1

Views: 3225

Answers (2)

StaticVariable
StaticVariable

Reputation: 5283

You can use json

echo json_encode( $row );

and in the main script

$result=json_decode($output);

and to print use echo $result->name;

Upvotes: 1

Lukasz Kujawa
Lukasz Kujawa

Reputation: 3096

On the remote server

echo serialize( $row );

in your first script

$array = unserialize( $output );

Upvotes: 1

Related Questions