Discussion:
mongo usage
Tim Dunphy
2013-07-06 18:42:07 UTC
Permalink
Hey all,

I'm trying to pick up some basic use of MongoDB using PHP.

I seem to have hit an early obstacle that I'd like your opinion on. I try
to pass an array to the mongo insert function, but for some reason the
function does not recognize the array I'm passing. Even though I can
perform a var_dump() on the array and see the contents.

Here's the output I'm seeing (with error):

Mongo Test Page array(6) { ["first_name"]=> string(5) "Peter"
["last_name"]=> string(6) "Parker" ["address"]=> string(16) "175 Fifth
Avenue" ["city"]=> string(8) "New York" ["state"]=> string(2) "NY"
["zip"]=> string(5) "10010" }

*Notice*: Undefined variable: addresses in */var/www/mongomaven/index.php* on
line *36*

*Fatal error*: Call to a member function insert() on a non-object in *
/var/www/mongomaven/index.php* on line *36*
*
*
And here's the code:

<html>
<head>
<title>Mongo Test</title>
</head>
<body>

Mongo Test Page
<?php



$connection = new Mongo();


$db = $connection->jfdb;

$collection = $db->addresses;

//$adresses = $connection->jfdb->adresses;

$address = array(
'first_name' => 'Peter',
'last_name' => 'Parker',
'address' => '175 Fifth Avenue',
'city' => 'New York',
'state' => 'NY',
'zip' => '10010', );

var_dump($address);

echo '<br />';

$addresses->insert($address);

?>
</body>
</html>


I'd appreciate any advice you might have.

Thanks,
Tim
--
GPG me!!

gpg --keyserver pool.sks-keyservers.net --recv-keys F186197B
Thomas Punt
2013-07-06 18:55:14 UTC
Permalink
Could the comma after the last element in your array be causing the problem?
Date: Sat, 6 Jul 2013 14:42:07 -0400
Subject: [PHP] mongo usage
Hey all,
I'm trying to pick up some basic use of MongoDB using PHP.
I seem to have hit an early obstacle that I'd like your opinion on. I try
to pass an array to the mongo insert function, but for some reason the
function does not recognize the array I'm passing. Even though I can
perform a var_dump() on the array and see the contents.
Mongo Test Page array(6) { ["first_name"]=> string(5) "Peter"
["last_name"]=> string(6) "Parker" ["address"]=> string(16) "175 Fifth
Avenue" ["city"]=> string(8) "New York" ["state"]=> string(2) "NY"
["zip"]=> string(5) "10010" }
*Notice*: Undefined variable: addresses in */var/www/mongomaven/index.php* on
line *36*
*Fatal error*: Call to a member function insert() on a non-object in *
/var/www/mongomaven/index.php* on line *36*
*
*
<html>
<head>
<title>Mongo Test</title>
</head>
<body>
Mongo Test Page
<?php
$connection = new Mongo();
$db = $connection->jfdb;
$collection = $db->addresses;
//$adresses = $connection->jfdb->adresses;
$address = array(
'first_name' => 'Peter',
'last_name' => 'Parker',
'address' => '175 Fifth Avenue',
'city' => 'New York',
'state' => 'NY',
'zip' => '10010', );
var_dump($address);
echo '<br />';
$addresses->insert($address);
?>
</body>
</html>
I'd appreciate any advice you might have.
Thanks,
Tim
--
GPG me!!
gpg --keyserver pool.sks-keyservers.net --recv-keys F186197B
Tim Dunphy
2013-07-06 19:14:04 UTC
Permalink
| Could the comma after the last element in your array be causing the
problem?

I tried removing it, but there was no change. Thanks for the suggestion!
Post by Thomas Punt
Could the comma after the last element in your array be causing the problem?
Date: Sat, 6 Jul 2013 14:42:07 -0400
Subject: [PHP] mongo usage
Hey all,
I'm trying to pick up some basic use of MongoDB using PHP.
I seem to have hit an early obstacle that I'd like your opinion on. I try
to pass an array to the mongo insert function, but for some reason the
function does not recognize the array I'm passing. Even though I can
perform a var_dump() on the array and see the contents.
Mongo Test Page array(6) { ["first_name"]=> string(5) "Peter"
["last_name"]=> string(6) "Parker" ["address"]=> string(16) "175 Fifth
Avenue" ["city"]=> string(8) "New York" ["state"]=> string(2) "NY"
["zip"]=> string(5) "10010" }
*Notice*: Undefined variable: addresses in
*/var/www/mongomaven/index.php* on
line *36*
*Fatal error*: Call to a member function insert() on a non-object in *
/var/www/mongomaven/index.php* on line *36*
*
*
<html>
<head>
<title>Mongo Test</title>
</head>
<body>
Mongo Test Page
<?php
$connection = new Mongo();
$db = $connection->jfdb;
$collection = $db->addresses;
//$adresses = $connection->jfdb->adresses;
$address = array(
'first_name' => 'Peter',
'last_name' => 'Parker',
'address' => '175 Fifth Avenue',
'city' => 'New York',
'state' => 'NY',
'zip' => '10010', );
var_dump($address);
echo '<br />';
$addresses->insert($address);
?>
</body>
</html>
I'd appreciate any advice you might have.
Thanks,
Tim
--
GPG me!!
gpg --keyserver pool.sks-keyservers.net --recv-keys F186197B
--
GPG me!!

gpg --keyserver pool.sks-keyservers.net --recv-keys F186197B
Jonathan Sundquist
2013-07-06 18:57:00 UTC
Permalink
You commented out the setting of yhe addresses variable
Post by Tim Dunphy
Hey all,
I'm trying to pick up some basic use of MongoDB using PHP.
I seem to have hit an early obstacle that I'd like your opinion on. I try
to pass an array to the mongo insert function, but for some reason the
function does not recognize the array I'm passing. Even though I can
perform a var_dump() on the array and see the contents.
Mongo Test Page array(6) { ["first_name"]=> string(5) "Peter"
["last_name"]=> string(6) "Parker" ["address"]=> string(16) "175 Fifth
Avenue" ["city"]=> string(8) "New York" ["state"]=> string(2) "NY"
["zip"]=> string(5) "10010" }
*Notice*: Undefined variable: addresses in */var/www/mongomaven/index.php* on
line *36*
*Fatal error*: Call to a member function insert() on a non-object in *
/var/www/mongomaven/index.php* on line *36*
*
*
<html>
<head>
<title>Mongo Test</title>
</head>
<body>
Mongo Test Page
<?php
$connection = new Mongo();
$db = $connection->jfdb;
$collection = $db->addresses;
//$adresses = $connection->jfdb->adresses;
$address = array(
'first_name' => 'Peter',
'last_name' => 'Parker',
'address' => '175 Fifth Avenue',
'city' => 'New York',
'state' => 'NY',
'zip' => '10010', );
var_dump($address);
echo '<br />';
$addresses->insert($address);
?>
</body>
</html>
I'd appreciate any advice you might have.
Thanks,
Tim
--
GPG me!!
gpg --keyserver pool.sks-keyservers.net --recv-keys F186197B
Tim Dunphy
2013-07-06 19:16:30 UTC
Permalink
| You commented out the setting of yhe addresses variable

Those were both equivalent ways of stating the same thing. I tried
substituting the other statement but there was no change:

$db = $connection->jfdb;

//$collection = $db->addresses;

$adresses = $connection->jfdb->adresses;

Thanks again!
Post by Jonathan Sundquist
You commented out the setting of yhe addresses variable
Post by Tim Dunphy
Hey all,
I'm trying to pick up some basic use of MongoDB using PHP.
I seem to have hit an early obstacle that I'd like your opinion on. I try
to pass an array to the mongo insert function, but for some reason the
function does not recognize the array I'm passing. Even though I can
perform a var_dump() on the array and see the contents.
Mongo Test Page array(6) { ["first_name"]=> string(5) "Peter"
["last_name"]=> string(6) "Parker" ["address"]=> string(16) "175 Fifth
Avenue" ["city"]=> string(8) "New York" ["state"]=> string(2) "NY"
["zip"]=> string(5) "10010" }
*Notice*: Undefined variable: addresses in
*/var/www/mongomaven/index.php* on
line *36*
*Fatal error*: Call to a member function insert() on a non-object in *
/var/www/mongomaven/index.php* on line *36*
*
*
<html>
<head>
<title>Mongo Test</title>
</head>
<body>
Mongo Test Page
<?php
$connection = new Mongo();
$db = $connection->jfdb;
$collection = $db->addresses;
//$adresses = $connection->jfdb->adresses;
$address = array(
'first_name' => 'Peter',
'last_name' => 'Parker',
'address' => '175 Fifth Avenue',
'city' => 'New York',
'state' => 'NY',
'zip' => '10010', );
var_dump($address);
echo '<br />';
$addresses->insert($address);
?>
</body>
</html>
I'd appreciate any advice you might have.
Thanks,
Tim
--
GPG me!!
gpg --keyserver pool.sks-keyservers.net --recv-keys F186197B
--
GPG me!!

gpg --keyserver pool.sks-keyservers.net --recv-keys F186197B
Matijn Woudt
2013-07-06 21:39:30 UTC
Permalink
Post by Tim Dunphy
| You commented out the setting of yhe addresses variable
Those were both equivalent ways of stating the same thing. I tried
$db = $connection->jfdb;
//$collection = $db->addresses;
$adresses = $connection->jfdb->adresses;
Thanks again!
You seem to spell the variable differently (1 'd' vs. 2 'd's)?

- Matijn
Tim Dunphy
2013-07-06 22:27:57 UTC
Permalink
| You seem to spell the variable differently (1 'd' vs. 2 'd's)?

Thanks! Fixed the type-o. Still no change.

$connection = new Mongo();


$db = $connection->jfdb;

//$collection = $db->addresses;

$adresses = $connection->jfdb->addresses;

Any other suggestions? Appreciated.

Tim
Post by Matijn Woudt
Post by Tim Dunphy
| You commented out the setting of yhe addresses variable
Those were both equivalent ways of stating the same thing. I tried
$db = $connection->jfdb;
//$collection = $db->addresses;
$adresses = $connection->jfdb->adresses;
Thanks again!
You seem to spell the variable differently (1 'd' vs. 2 'd's)?
- Matijn
--
GPG me!!

gpg --keyserver pool.sks-keyservers.net --recv-keys F186197B
Tim Streater
2013-07-06 22:49:00 UTC
Permalink
Post by Tim Dunphy
| You seem to spell the variable differently (1 'd' vs. 2 'd's)?
Thanks! Fixed the type-o. Still no change.
$connection = new Mongo();
$db = $connection->jfdb;
//$collection = $db->addresses;
$adresses = $connection->jfdb->addresses;
~~~~~~~~~
Post by Tim Dunphy
Any other suggestions? Appreciated.
Fix the other typo.
--
Cheers -- Tim
Tim Dunphy
2013-07-06 22:52:47 UTC
Permalink
Thanks. Sorry to bug you guys with this. That did it. sigh
Post by Tim Streater
Post by Tim Dunphy
| You seem to spell the variable differently (1 'd' vs. 2 'd's)?
Thanks! Fixed the type-o. Still no change.
$connection = new Mongo();
$db = $connection->jfdb;
//$collection = $db->addresses;
$adresses = $connection->jfdb->addresses;
~~~~~~~~~
Post by Tim Dunphy
Any other suggestions? Appreciated.
Fix the other typo.
--
Cheers -- Tim
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--
GPG me!!

gpg --keyserver pool.sks-keyservers.net --recv-keys F186197B
Loading...