Page 1 of 1

Running Curl from PHP CLI

Posted: Tue Sep 15, 2009 2:17 pm
by chopper_pc
Hi,
WIN32 IIS (2003 Server)
I have a basic PHP script that runs fine on IIS to pull an array from an MSSQL DB and use Curl to post to an external server that uses the information from my DB.
I now need to run the script from the CLI to run via the task manager.

Code: Select all

 
while($row = mssql_fetch_array($result))
{
  echo "<li>" . $row["CreatedDate"] . $row["PartNumber"] . $row["Quantity"] . $row["Manufacturer"] . $row["Condition"] . $row["Description"] . $row["Hot"] ."</li>";
 
  require_once('CurlClass.php');
  $cc = new cURL();
  $cc->post('http://www.blabla.com',part_number=$row["PartNumber"]&quantity=$row["Quantity"]&manufacturer=$row["Manufacturer"]&condition=$row["Condition"]&description=$row["Description"]&hot=$row["Hot"]');
 
Worked fine when done on the web. Using the same code calling from a batch script using C:\path\to\PHP\php.exe C:\path\to\script\foo.php returns good results when it echoes to the sreen but my Curl output on the external server is looses the variable values. It posts literally :

[part_number] => $row[\"PartNumber\"] ....................


Any ideas on what I'm doing wrong here, I have found nothing searching the net.

Thanks...

Re: Running Curl from PHP CLI

Posted: Tue Sep 15, 2009 4:45 pm
by gigabit
Does the CURL class use the built in PHP curl functions?

Re: Running Curl from PHP CLI

Posted: Tue Sep 15, 2009 4:59 pm
by Mirge

Code: Select all

 
$cc->post('http://www.blabla.com',part_number=$row["PartNumber"]&quantity=$row["Quantity"]&manufacturer=$row["Manufacturer"]&condition=$row["Condition"]&description=$row["Description"]&hot=$row["Hot"]');
 
The above is your code... and it SHOULD be throwing a parse error.

After the first argument (URL: http://www.blabla.com), your 2nd argument is NOT enclosed within quotes... sort of. It has an ending single quote, but not a starting quote. In addition, variables within single quotes do not interpolate... you would need to use double quotes.

Example:

Code: Select all

 
$foo = "bar";
 
print '$foo'; // Output: $foo
print "$foo"; // Output: bar
print $foo; // Output: bar