Cloud Datastore PHP returning 0 results











up vote
0
down vote

favorite












So I tried to first see if my PHP can talk to Datastore and retrieve data.
I created two entities under the kind "keypad_research".



This is how my PHP looks like:



<?php
require __DIR__ . '/../../vendor/autoload.php';
use GoogleCloudDatastoreDatastoreClient;
use GoogleCloudDatastoreEntity;
$projectId = "__my projectID__";
$datasetId = $projectId;
$datastore = new DatastoreClient(['projectId' => $projectId]);

function getlist($datastore){
$query = $datastore->query()
->kind('keypad_research')
->start($cursor);

$results = $datastore->runQuery($query);
$entries = ;
$count = 0;
foreach ($results as $entity) {
$count++;
}

echo $count; // this shows me '0' results even when I have 2 entities.
}
getlist($datastore);
?>


As you can see in the echo statement in the end, it is resulting in 0 rows of data.



Do I need to do any addition configuration or edit my PHP to be able to read from datastore?



My very basic attempt at reading data from datastore using PHP is failing.



Any advice is appreciated.










share|improve this question


























    up vote
    0
    down vote

    favorite












    So I tried to first see if my PHP can talk to Datastore and retrieve data.
    I created two entities under the kind "keypad_research".



    This is how my PHP looks like:



    <?php
    require __DIR__ . '/../../vendor/autoload.php';
    use GoogleCloudDatastoreDatastoreClient;
    use GoogleCloudDatastoreEntity;
    $projectId = "__my projectID__";
    $datasetId = $projectId;
    $datastore = new DatastoreClient(['projectId' => $projectId]);

    function getlist($datastore){
    $query = $datastore->query()
    ->kind('keypad_research')
    ->start($cursor);

    $results = $datastore->runQuery($query);
    $entries = ;
    $count = 0;
    foreach ($results as $entity) {
    $count++;
    }

    echo $count; // this shows me '0' results even when I have 2 entities.
    }
    getlist($datastore);
    ?>


    As you can see in the echo statement in the end, it is resulting in 0 rows of data.



    Do I need to do any addition configuration or edit my PHP to be able to read from datastore?



    My very basic attempt at reading data from datastore using PHP is failing.



    Any advice is appreciated.










    share|improve this question
























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      So I tried to first see if my PHP can talk to Datastore and retrieve data.
      I created two entities under the kind "keypad_research".



      This is how my PHP looks like:



      <?php
      require __DIR__ . '/../../vendor/autoload.php';
      use GoogleCloudDatastoreDatastoreClient;
      use GoogleCloudDatastoreEntity;
      $projectId = "__my projectID__";
      $datasetId = $projectId;
      $datastore = new DatastoreClient(['projectId' => $projectId]);

      function getlist($datastore){
      $query = $datastore->query()
      ->kind('keypad_research')
      ->start($cursor);

      $results = $datastore->runQuery($query);
      $entries = ;
      $count = 0;
      foreach ($results as $entity) {
      $count++;
      }

      echo $count; // this shows me '0' results even when I have 2 entities.
      }
      getlist($datastore);
      ?>


      As you can see in the echo statement in the end, it is resulting in 0 rows of data.



      Do I need to do any addition configuration or edit my PHP to be able to read from datastore?



      My very basic attempt at reading data from datastore using PHP is failing.



      Any advice is appreciated.










      share|improve this question













      So I tried to first see if my PHP can talk to Datastore and retrieve data.
      I created two entities under the kind "keypad_research".



      This is how my PHP looks like:



      <?php
      require __DIR__ . '/../../vendor/autoload.php';
      use GoogleCloudDatastoreDatastoreClient;
      use GoogleCloudDatastoreEntity;
      $projectId = "__my projectID__";
      $datasetId = $projectId;
      $datastore = new DatastoreClient(['projectId' => $projectId]);

      function getlist($datastore){
      $query = $datastore->query()
      ->kind('keypad_research')
      ->start($cursor);

      $results = $datastore->runQuery($query);
      $entries = ;
      $count = 0;
      foreach ($results as $entity) {
      $count++;
      }

      echo $count; // this shows me '0' results even when I have 2 entities.
      }
      getlist($datastore);
      ?>


      As you can see in the echo statement in the end, it is resulting in 0 rows of data.



      Do I need to do any addition configuration or edit my PHP to be able to read from datastore?



      My very basic attempt at reading data from datastore using PHP is failing.



      Any advice is appreciated.







      google-cloud-datastore






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 20 at 7:03









      ssdesign

      1,04062241




      1,04062241
























          2 Answers
          2






          active

          oldest

          votes

















          up vote
          1
          down vote



          accepted










          If you are querying a non-default namespace, you need to identify the namespace when you initialize your client:



          $datastore = new DatastoreClient([
          'projectId' => $projectId,
          'namespaceId' => 'my-namespace'
          ]);





          share|improve this answer





















          • WOW, such an important information is nowhere to be found in the documentation. Thanks a ton, this worked.
            – ssdesign
            Nov 21 at 5:12


















          up vote
          1
          down vote













          I've been able to get the number of entities in a kind using your code, only editing the second line and adding the variable $cursor=null:



          <?php

          require __DIR__ . '/vendor/autoload.php';
          # Imports the Google Cloud client library
          use GoogleCloudDatastoreDatastoreClient;
          use GoogleCloudDatastoreEntity;

          $projectId = "__my projectID__";
          $datasetId = $projectId;
          $datastore = new DatastoreClient(['projectId' => $projectId]);

          function getlist($datastore){
          $cursor=null;
          $query = $datastore->query()
          ->kind('keypad_research')
          ->start($cursor);

          $results = $datastore->runQuery($query);
          $entries = ;
          $count = 0;
          foreach ($results as $entity) {
          $count++;
          }

          echo $count; // this shows me '0' results even when I have 2 entities.
          }
          getlist($datastore);
          ?>





          share|improve this answer





















          • Oh thats great. But even after adding the cursor code I don't get any results. Do you know if there could be Authentication issue? Do I need anything else other than this code for it to work?
            – ssdesign
            Nov 20 at 18:39












          • Could the namespace be a problem? My Kind is not default namespace, it has specific namespace defined.
            – ssdesign
            Nov 20 at 21:23











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53387814%2fcloud-datastore-php-returning-0-results%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          1
          down vote



          accepted










          If you are querying a non-default namespace, you need to identify the namespace when you initialize your client:



          $datastore = new DatastoreClient([
          'projectId' => $projectId,
          'namespaceId' => 'my-namespace'
          ]);





          share|improve this answer





















          • WOW, such an important information is nowhere to be found in the documentation. Thanks a ton, this worked.
            – ssdesign
            Nov 21 at 5:12















          up vote
          1
          down vote



          accepted










          If you are querying a non-default namespace, you need to identify the namespace when you initialize your client:



          $datastore = new DatastoreClient([
          'projectId' => $projectId,
          'namespaceId' => 'my-namespace'
          ]);





          share|improve this answer





















          • WOW, such an important information is nowhere to be found in the documentation. Thanks a ton, this worked.
            – ssdesign
            Nov 21 at 5:12













          up vote
          1
          down vote



          accepted







          up vote
          1
          down vote



          accepted






          If you are querying a non-default namespace, you need to identify the namespace when you initialize your client:



          $datastore = new DatastoreClient([
          'projectId' => $projectId,
          'namespaceId' => 'my-namespace'
          ]);





          share|improve this answer












          If you are querying a non-default namespace, you need to identify the namespace when you initialize your client:



          $datastore = new DatastoreClient([
          'projectId' => $projectId,
          'namespaceId' => 'my-namespace'
          ]);






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 20 at 23:34









          JRLtechwriting

          1,076514




          1,076514












          • WOW, such an important information is nowhere to be found in the documentation. Thanks a ton, this worked.
            – ssdesign
            Nov 21 at 5:12


















          • WOW, such an important information is nowhere to be found in the documentation. Thanks a ton, this worked.
            – ssdesign
            Nov 21 at 5:12
















          WOW, such an important information is nowhere to be found in the documentation. Thanks a ton, this worked.
          – ssdesign
          Nov 21 at 5:12




          WOW, such an important information is nowhere to be found in the documentation. Thanks a ton, this worked.
          – ssdesign
          Nov 21 at 5:12












          up vote
          1
          down vote













          I've been able to get the number of entities in a kind using your code, only editing the second line and adding the variable $cursor=null:



          <?php

          require __DIR__ . '/vendor/autoload.php';
          # Imports the Google Cloud client library
          use GoogleCloudDatastoreDatastoreClient;
          use GoogleCloudDatastoreEntity;

          $projectId = "__my projectID__";
          $datasetId = $projectId;
          $datastore = new DatastoreClient(['projectId' => $projectId]);

          function getlist($datastore){
          $cursor=null;
          $query = $datastore->query()
          ->kind('keypad_research')
          ->start($cursor);

          $results = $datastore->runQuery($query);
          $entries = ;
          $count = 0;
          foreach ($results as $entity) {
          $count++;
          }

          echo $count; // this shows me '0' results even when I have 2 entities.
          }
          getlist($datastore);
          ?>





          share|improve this answer





















          • Oh thats great. But even after adding the cursor code I don't get any results. Do you know if there could be Authentication issue? Do I need anything else other than this code for it to work?
            – ssdesign
            Nov 20 at 18:39












          • Could the namespace be a problem? My Kind is not default namespace, it has specific namespace defined.
            – ssdesign
            Nov 20 at 21:23















          up vote
          1
          down vote













          I've been able to get the number of entities in a kind using your code, only editing the second line and adding the variable $cursor=null:



          <?php

          require __DIR__ . '/vendor/autoload.php';
          # Imports the Google Cloud client library
          use GoogleCloudDatastoreDatastoreClient;
          use GoogleCloudDatastoreEntity;

          $projectId = "__my projectID__";
          $datasetId = $projectId;
          $datastore = new DatastoreClient(['projectId' => $projectId]);

          function getlist($datastore){
          $cursor=null;
          $query = $datastore->query()
          ->kind('keypad_research')
          ->start($cursor);

          $results = $datastore->runQuery($query);
          $entries = ;
          $count = 0;
          foreach ($results as $entity) {
          $count++;
          }

          echo $count; // this shows me '0' results even when I have 2 entities.
          }
          getlist($datastore);
          ?>





          share|improve this answer





















          • Oh thats great. But even after adding the cursor code I don't get any results. Do you know if there could be Authentication issue? Do I need anything else other than this code for it to work?
            – ssdesign
            Nov 20 at 18:39












          • Could the namespace be a problem? My Kind is not default namespace, it has specific namespace defined.
            – ssdesign
            Nov 20 at 21:23













          up vote
          1
          down vote










          up vote
          1
          down vote









          I've been able to get the number of entities in a kind using your code, only editing the second line and adding the variable $cursor=null:



          <?php

          require __DIR__ . '/vendor/autoload.php';
          # Imports the Google Cloud client library
          use GoogleCloudDatastoreDatastoreClient;
          use GoogleCloudDatastoreEntity;

          $projectId = "__my projectID__";
          $datasetId = $projectId;
          $datastore = new DatastoreClient(['projectId' => $projectId]);

          function getlist($datastore){
          $cursor=null;
          $query = $datastore->query()
          ->kind('keypad_research')
          ->start($cursor);

          $results = $datastore->runQuery($query);
          $entries = ;
          $count = 0;
          foreach ($results as $entity) {
          $count++;
          }

          echo $count; // this shows me '0' results even when I have 2 entities.
          }
          getlist($datastore);
          ?>





          share|improve this answer












          I've been able to get the number of entities in a kind using your code, only editing the second line and adding the variable $cursor=null:



          <?php

          require __DIR__ . '/vendor/autoload.php';
          # Imports the Google Cloud client library
          use GoogleCloudDatastoreDatastoreClient;
          use GoogleCloudDatastoreEntity;

          $projectId = "__my projectID__";
          $datasetId = $projectId;
          $datastore = new DatastoreClient(['projectId' => $projectId]);

          function getlist($datastore){
          $cursor=null;
          $query = $datastore->query()
          ->kind('keypad_research')
          ->start($cursor);

          $results = $datastore->runQuery($query);
          $entries = ;
          $count = 0;
          foreach ($results as $entity) {
          $count++;
          }

          echo $count; // this shows me '0' results even when I have 2 entities.
          }
          getlist($datastore);
          ?>






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 20 at 12:27









          Alex Riquelme

          43718




          43718












          • Oh thats great. But even after adding the cursor code I don't get any results. Do you know if there could be Authentication issue? Do I need anything else other than this code for it to work?
            – ssdesign
            Nov 20 at 18:39












          • Could the namespace be a problem? My Kind is not default namespace, it has specific namespace defined.
            – ssdesign
            Nov 20 at 21:23


















          • Oh thats great. But even after adding the cursor code I don't get any results. Do you know if there could be Authentication issue? Do I need anything else other than this code for it to work?
            – ssdesign
            Nov 20 at 18:39












          • Could the namespace be a problem? My Kind is not default namespace, it has specific namespace defined.
            – ssdesign
            Nov 20 at 21:23
















          Oh thats great. But even after adding the cursor code I don't get any results. Do you know if there could be Authentication issue? Do I need anything else other than this code for it to work?
          – ssdesign
          Nov 20 at 18:39






          Oh thats great. But even after adding the cursor code I don't get any results. Do you know if there could be Authentication issue? Do I need anything else other than this code for it to work?
          – ssdesign
          Nov 20 at 18:39














          Could the namespace be a problem? My Kind is not default namespace, it has specific namespace defined.
          – ssdesign
          Nov 20 at 21:23




          Could the namespace be a problem? My Kind is not default namespace, it has specific namespace defined.
          – ssdesign
          Nov 20 at 21:23


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53387814%2fcloud-datastore-php-returning-0-results%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          404 Error Contact Form 7 ajax form submitting

          How to know if a Active Directory user can login interactively

          Refactoring coordinates for Minecraft Pi buildings written in Python