Why Does This Return Resource Id #2

Why does this return Resource id #2?

Because you get a mysql ressource when you do a mysql_query().

Use something like mysql_fetch_assoc() to get the next row. It returns an array with the column names as indices. In your case it's probably COUNT(*).

Here's a fix and some minor improvements of your snippet:

$rt = mysql_query("SELECT COUNT(*) FROM persons") or die(mysql_error());
$row = mysql_fetch_row($rt);
if($row)
echo "<h1>Number:</h1>" . $row[0];

If you need to get all rows of the resultset use this snippet:

while($row = mysql_fetch_assoc($rt)) {
var_dump($row);
}

Resource id #2 response from curl php

Try this code:

CURLOPT_HTTPHEADER is not required if you are passing an array or string.

Added

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
to bypass SSL

<?php
$url = 'https://api.sandbox.paypal.com/v1/oauth2/token';
$info = array(
'grant_type' =>'client_credentials'
);
$post_field_string = http_build_query($info, '', '&');
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_USERPWD,'ATKsMxDPf23rhQTgixcTYxLfuJoBsTiIRyaSQW_4J8_rNoVQsXHQkBjmBN0z:EOvF6RBizzf9qH2eA_s3PYmQk--smR6Xe8kDws228lq5pA0IebXTg902FY7f');
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_field_string);
curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_HEADER,1);
$exec = curl_exec($ch);
echo '<pre>';
print_r($exec);
curl_close($ch);

Response:

HTTP/1.1 200 OK Server: Apache-Coyote/1.1

PROXY_SERVER_INFO: host=slcsbjava3.slc.paypal.com;threadId=234251 Paypal-Debug-Id:976e66d30ed12

SERVER_INFO:
identitysecuretokenserv:v1.oauth2.token&CalThreadId=138269&TopLevelTxnStartTime=14666662622&Host=slcsbidensectoken502.slc.paypal.com&pid=17346

CORRELATION-ID: 976e66d30ed12

Date: Wed, 04 Jun 2014 10:21:51 GMT

Content-Type: application/json

Transfer-Encoding: chunked

{
"scope": "openid",
"access_token": "A015wXWyeWOj3CprA4dz8uvB.AgGUE-A-p6SuQhw..rmGug",
"token_type": "Bearer",
"expires_in": 28800
}

curl append Resource id #2 to the output

curl_init() returns a resource (see http://php.net/manual/en/function.curl-init.php)

Hence echo $curl; or echo curl_init(); will give you something like Resource id #2.

You are probably looking for something like this:

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://localhost/api/11122233A");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
echo $output;

For further details see http://php.net/manual/en/function.curl-exec.php


As you're saying curl works for you via the command line (i. e. $ curl ...) there's a workaround for you. Just exec() you curl command.

Example:

$output = exec('curl http://localhost/api/11122233A');
echo $output;

Resource id returned when querying in php

Read the manual

Return Values

For SELECT, SHOW, DESCRIBE, EXPLAIN and other statements returning
resultset, mysql_query() returns a resource on success, or FALSE on
error.

So what you are seeing is expected behaviour.

If you're trying to get the results of your query you need to use one of the many functions available such as mysql_fetch_assoc().

FYI, you shouldn't use mysql_* functions in new code. They are no longer maintained and are officially deprecated. See the red box? Learn about prepared statements instead, and use PDO, or MySQLi - this article will help you decide which. If you choose PDO, here is a good tutorial.

Getting Resource id #26 PHP Error

You will need fetch the query result like this

$R = mysql_query("SELECT * FROM Replies WHERE tid='$gS->ID' ORDER BY ID DESC LIMIT     1"); 

since $R is just one result you don't need to use a while. use mysql_fetch_assoc()

 $row=  mysql_fetch_assoc($R);

to print use

<?php echo $row['FieldName'];?>

Try to update to mysqli or PDO

Why shouldn't I use mysql_* functions in PHP?



Related Topics



Leave a reply



Submit