tags:

views:

209

answers:

4

Is there some NoSQL solution written in PHP (perhaps NoSQL front end to MySQL or PostgreSQL)? I need to store and search for key/value pairs in my PHP scripts, but I need to run it on webhosing where I cannot to install anything (so CouchDB, MongoDB etc. is not solution for me). I need something that supports somethinq like this:

// select * from things where x=3 and y="foo" 
db.things.find( { x : 3, y : "foo" } ); 

Thanks.

Edit: I am looking for a simple NoSQL (en.wikipedia.org/wiki/NoSQL) document-oriented database (en.wikipedia.org/wiki/Document-oriented_database).

A: 

Check out the DBA functions, they may already be compiled in to your PHP.

Edit: Or, given the updated replies in your post, Amazon SimpleDB sounds like it might be a good match. I don't believe there are any external dependencies that need to be installed.

Alex Howansky
Thank for the answer but I need a little more advanced solution. I am sorry, my original question was not clear enough, I added an example.
Petr
A: 

Isn't SQLlite (or SQLlite3 for PHP 5.3+) available ? That would be weird because it's supposed to be enabled by default with PHP 5...

** EDIT **

A suggestion would be to have a normal SQL database (ex: SQLlite, MySQL, etc.) and store your objects in their serialized form.

Something like

$data = new DataClass();
$data->x = 3;
$data->y = 'foo';

$serialized_data = addslashes(serialize($data));
mysql_query("INSERT INTO data_table (x,y,data) VALUES ('{$data->x}', '{$data->y}', '{$serialized_data}')")

//Then To SELECT...

$link = mysql_query("SELECT data FROM data_table WHERE x=3 AND y='foo'");
$row = mysql_fetch_array($link)
$data = unserialize($row['data'])

This way, you can perform query and store virtually any kind of objects. All you need to do is to have specific columns for the values you wish to "index". You could even have a different table for every class for convenience.

Yanick Rochon
How is that NoSQL?
Alexander Sagen
select * from things where x=3 and y="foo" is already SQL :)
Slavic
so far, SQLlite would fit perfectly what you are describing. It's even supported by PDO... and it's NoSQL too
Yanick Rochon
SQLite is **not** a [NoSQL](http://en.wikipedia.org/wiki/NoSQL) db.
Gordon
Well I need to store "objects" whith different sets of atributes (and stored in non-normalized form). Unfortunatelly relational database is not suitable for me.
Petr
by definition (http://en.wikipedia.org/wiki/NoSQL) it does
Yanick Rochon
@Yanick there is not one mention of SQLite in the Wikipedia article. NoSQL implies non-relational datastorage that does not use SQL for querying.
Gordon
@Gordon, "not only sql" is the definition. Even if SQLlite is not suggested, it does fit the description in some way. Besides, the question itself uses SQL... so I fail to see why you are arguing this
Yanick Rochon
@Yanick Rochon - the SQL in the example comment is only for clarification what the code should do
Petr
@Yanick because you claim SQLite is a NoSQL db, which it isnt. SQLite is a self-contained, serverless, zero-configuration, transactional SQL database engine.
Gordon
@Gordon, SQLlite does not support FOREIGN KEY constraints... which to me is pretty close to NoSQL definition of a being a "not relational" dababase. But all this is beside the point.
Yanick Rochon
@Yanick [SQLite supports Foreign Key Constraints as of version 3.6.19](http://sqlite.org/foreignkeys.html)
Gordon
well, that's good to know... even if I've never used SQLlite (nor do I plan to)
Yanick Rochon
@Yanick you might also want to link to the [SQLite3 libs](http://www.php.net/manual/en/class.sqlite3.php) instead of the old 2.x libs, though the new lib requires PHP 5.3 - Interesting edit btw.
Gordon
@Gordon, not that I want to hold back on technologies, quite the opposite actually, but I'm not even sure most web hosts have gone PHP 5.3 yet... but I'll update my post nevertheless
Yanick Rochon
PDO also supports SQLite 3 DBs since at least PHP 5.1: http://php.net/manual/en/ref.pdo-sqlite.php.
Alix Axel
@Yanick Rochon Thnaks for the edit, it is a interesting solution but it is not for me. You must decide what columns will be indexed when you create the database and first of all the indexed colums must present in every object.
Petr
@Petr, there may be a project doing exactly what you want, but I don't think I know any. In any case, good luck then.
Yanick Rochon
yep sqlite is probably the best fit since you cant install anything and its still a "database". who cares if its nosql or not - it's simple.
Tobias
A: 

FIRST: if you try to use something done in PHP your script's performance will be terrible.

there are few project where you can use something in top of mysql to have a key/value storage

try this and take a look to this great implementation of friendfeed

Gabriel Sosa