Discussion on MyDB - Your Flat-File Database

GreenyCode does not currently provide support for this item.

11 comments found.

It is only backend.

How do you create key constraints and AutoInc columns? Also how do you define data types? Regards.

MyDB automatically generate column id so you don’t need to create it when creating table.
If you want to get it on select you can write: $this->Select(“tb”, array(‘id’, ‘other column’));
What do you mean of question with data types?
Thank you for purchasing :)

Hi there, by data type I mean what happen if you want a column to be VARCHAR another to be INT, etc

Hi, thank you, it is really good DB

but I have 2 questions 1) How I can use “automatically generate column id” now I do like this: $id = $db->RowCount(‘reviews’); $db->Insert(‘reviews’, array(‘id’ => $id, ....);

2) When I want RowCount or Select from empty table I see this error:

Warning: Invalid argument supplied for foreach() in /inc/MyDB.Class.php on line 179

Could you fix this error? I want see result NULL, if table empty, but not ERROR

thank you

Now i create update. This bugs are fixed.
1) Now Insert function is returning column id: $id = $db->Insert(...);
2) RowCount return 0 when table is empty.
Thanks :)

thank you, How I can do id auto increment?

Id is automatically created as auto increment.

Is there a online documentation i can see? I am interested in this but i need to see a doc first.

Also if i want to add data to a database and the table does not exist, does it automatically create the table?


I think you should review the RowCount() method.

I have this table:

Array ( [0] => Array ( [name] => Franco [surname] => Magliozzi )

[1] => Array
        [name] => Rudy
        [surname] => Scafili


When I call $db->RowCount(‘users’, array(‘name’=> ‘Franco’));

It returns 1

When I call $db->RowCount(‘users’, array(‘name’=> ‘Rudy’));

It returns 2

I don’t know what this means. You will expect from a RowCount() method to return the numbers of rows found in the table which meets the conditions in where clause.

This function could be useful to check if a record already exist in the table and if it does will return the number of records, and in my case has to be 1 in both calls.



Fixed ! Now i create update :)

Thanks for the update.

Many thanks for your support for this nice and easy to use script.

Will be possible for you to add a method to check if a table exist?


The current method CheckExist($tb,$columns) requires a table name and a column to make a check.

In my application the tables are created by default and the users will populate them when they need to.

I need to make a check if the table exist in order to activate for the user the option to populate it.



i have $db->Insert(‘domains’,array(‘domain’ => $_POST[“domainNameList”],’expire’ => $json_a->expiration_date0)); how to chek if $_POST[“domainNameList”] exist in db ???

Why I see this error? How I can fix it?

PHP Warning: array_flip(): Can only flip STRING and INTEGER values! in /inc/MyDB.Class.php on line 320

Hi, this looks to be a great script, and potentially very useful but can you say what happens when multiple uses read and write to the database (...db file) at the same time. Is the file locked somehow to avoid corruption of the data?

ROWCOUNT Hi – I want to count the number of rows, but $db->RowCount(‘pairs’) return 0. But there is two rows, and I can extract data fine? Can you help? /Martin

Any documentation?