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.
google-cloud-datastore
add a comment |
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.
google-cloud-datastore
add a comment |
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.
google-cloud-datastore
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
google-cloud-datastore
asked Nov 20 at 7:03
ssdesign
1,04062241
1,04062241
add a comment |
add a comment |
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'
]);
WOW, such an important information is nowhere to be found in the documentation. Thanks a ton, this worked.
– ssdesign
Nov 21 at 5:12
add a comment |
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);
?>
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
add a comment |
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'
]);
WOW, such an important information is nowhere to be found in the documentation. Thanks a ton, this worked.
– ssdesign
Nov 21 at 5:12
add a comment |
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'
]);
WOW, such an important information is nowhere to be found in the documentation. Thanks a ton, this worked.
– ssdesign
Nov 21 at 5:12
add a comment |
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'
]);
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'
]);
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
add a comment |
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
add a comment |
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);
?>
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
add a comment |
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);
?>
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
add a comment |
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);
?>
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);
?>
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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