selectObjectContent.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. require dirname(__FILE__) . '/../vendor/autoload.php';
  3. $secretId = "COS_SECRETID";
  4. $secretKey = "COS_SECRETKEY";
  5. $region = "ap-beijing";
  6. $cosClient = new Qcloud\Cos\Client(array(
  7. 'region' => $region,
  8. 'schema' => 'https',
  9. 'credentials'=> array(
  10. 'secretId' => $secretId ,
  11. 'secretKey' => $secretKey
  12. )
  13. ));
  14. try {
  15. $result = $cosClient->selectObjectContent(array(
  16. 'Bucket' => $bucket,
  17. 'Key' => $key,
  18. 'Expression' => 'Select * from COSObject s',
  19. 'ExpressionType' => 'SQL',
  20. 'InputSerialization' => array(
  21. 'CompressionType' => 'None',
  22. 'CSV' => array(
  23. 'FileHeaderInfo' => 'NONE',
  24. 'RecordDelimiter' => '\n',
  25. 'FieldDelimiter' => ',',
  26. 'QuoteEscapeCharacter' => '"',
  27. 'Comments' => '#',
  28. 'AllowQuotedRecordDelimiter' => 'FALSE'
  29. )
  30. ),
  31. 'OutputSerialization' => array(
  32. 'CSV' => array(
  33. 'QuoteField' => 'ASNEEDED',
  34. 'RecordDelimiter' => '\n',
  35. 'FieldDelimiter' => ',',
  36. 'QuoteCharacter' => '"',
  37. 'QuoteEscapeCharacter' => '"'
  38. )
  39. ),
  40. 'RequestProgress' => array(
  41. 'Enabled' => 'FALSE'
  42. )
  43. ));
  44. foreach ($result['Data'] as $data) {
  45. print_r($data);
  46. }
  47. } catch (\Exception $e) {
  48. echo($e);
  49. }