Currently I am working with a commercial project with PHP. I think this question not really apply to PHP for all programming language, just want to discuss how your guys solve it.
I work in MVC framework (CodeIgniter).
all the database transaction code in model class.
Previously, I seperate different search criteria with different function name.
Just an example
function get_student_detail_by_ID($id){}
function get_student_detail_by_name($name){}
as you can see the function actually can merge to one, just add a parameter for it. But something you are rushing with project, you won't look back previously got what similar function just make some changes can meet the goal. In this case, we found that there is a lot function there and hard to maintenance.
Recently, we try to group the entity to one ultimate search
something like this
function get_ResList($is_row_count=FALSE, $record_start=0, $arr_search_criteria='', $paging_limit=20, $orderby='name', $sortdir='ASC')
we try to make this function to fit all the searching criteria. However, our system getting bigger and bigger, the search criteria not more 1-2 tables. It require join with other table with different purpose.
What we had done is using IF ELSE,
if(bla bla bla)
{
$sql_join = JOIN_SOME_TABLE;
$sql_where = CONDITION;
}
at the end, we found that very hard to maintance the function. it is very hard to debug as well.
I would like to ask your opinion, what is the commercial solution they solve this kind of issue, how to define a function and how to revise it. I think this is link project management skill. Hope you willing to share with us.
Thanks.
If you're using codeigniter, just use:
http://www.overzealous.com/dmz/
I don't know what I even used to do without it.
Congratulations, you have invented an ORM :)
There are plenty of commercial ORM solutions but, in my opinion, all they no better than yours. And I'd go for good ol' SQL.
After I did some research on ORM vs Active Record. For my situation I didn't find a lot of help by switching to ORM will help me better.
I found out that ORM is not do very in READ data. But good in Create, Update, and Delete.
My current solution is every model recompile the my own OR_WHERE() / AND_WHERE(), before pass to the $this->db->query(). It is more easy to maintain and customize.
Related
Title doesn't make too much sense, but I will try to explain further.
I am currently making a website (a game), and I currently have different folders for users/ranks etc, each with their own config and class.****.php file.
I am new to PHP/MySQL and now it seems like having these functions seperately with their own config.php to connect to the database is not the greatest idea.
If I want to fetch, let's say, username and rank, then I could be object-oriented and have a getter for those in each class.****.php file, or I could fetch it inside the file required. However, that's gonna be a lot of "SELECT FROM" in each file, which seems pretty unecessary.
Is there a different approach that I haven't thought about, or should I have all the functions in one file?
Feel free to ask questions if I am too vague.
Thanks in advance.
You might want to look at ORM frameworks. How do they work?
You fetch data in an OO way and get "entities"-rows which you can manipulate with your own functions. In some cases you may never have to write SQL. Here are some examples:
General purpose /Light-weight/Simple:
RedBeanPHP
IdiORM
Advanced/Full-fledged/Feature-rich
Eloquent
Doctrine
The list is endless. Just try each one of those and see what works for you
I have the following issue (I am trying to give the full context, if you are in a hurry, skip to the last paragraph):
We need to create a multilanguage support for a project. Our current database is MySQL.
Since the structure would need to change pretty much to allow it in the current DB, we got to the conclusion that the "classic" approach is not optimal.
By classic I mean adding lang tables, linking them with FKs, etc.
So we thought "let's save langs on file on disk". We analyzed that and is easier to implement, and looks ok as a solution. But then we got into the issue "what about concurrent access - we would need to implement something for this".
So we said... why not use a no sql db for this? It deals with concurrent access/lock, is outside our main db, is fast, scalable.
At first glance this looks like a good solution and we are willing to give it a try. But since we lack the experience with no sql... can any1 tell us if this is a good/bad idea and why (I explained how we got here and why we thought is a good idea)?
I was wondering if someone can help be to point me to an example for a "Best Practice" example for a sortable, searchable datagrid in Symfony2 with the doctrine ORM.
I always see Tutorials with the implementation of some data, generating Entity and so forth, but some/all lack the code how to enable Pagination, how can the user search in multiple fields from the frontend and how to handle the ordering after a field the user chooses to.
Before some folks now think I'm stupid, of course i can make a GET Variable and just make an IF clause to ask for it but i would really appreciate a best Practice example so i know how i am supposed to handle it.
Right now I'm thinking about an open source project for a Organisation system, so i will have many Tables i have to join and many datagrids to display. I would really love to get it in a right way so i don't have to write it all over again when the community is laughing at my code...
Thank you for reading and your help.
I use apy data grid bundle https://github.com/Abhoryo/APYDataGridBundle
It works very well and it's very simple to use
For your goal, you can take a look a SonataAdminBundle in which you can describe by yaml, for instance, you entities relations, search operands, and you'll have a full application to do CRUD and search without much trouble. I setup my basic crud/search operations on the 20 basic entities in a day or two.
I honestly don't know how sonata is organized and if the datagrid is "extractable" or if you could use it as a service, but I believe is a good starting point.
I am currently working on a 'simple' social network style in PHP. I call it 'simple' because it's not the classic example-type website; I just try and keep it as simple is possible;
So I basically am on MongoDB and have a two collection structure: the users table, which is something like
{ user:'test', pass:'123456', name:'foobar', info:'hello' }
and a posts table:
{ user:'test', message:'this is a test post' }
I simplified it all to make or more readable at first sight.
As said I am using MongoDB currently, working great and all but, I just read a bit about Cassandra and was wondering if it could be a better choice, given its simpler scaling features (I could basically do it myself instead of having to rely on MongoLab or MongoHQ);
But I am not sure if this could be a good idea as I am making use of dynamic queries.
Messaging and Relationships are not taken into consideration, I am using Redis for this; The switch would only be related to the registration of the users, search, and their posts.
Any ideas if I should keep with Mongo, or if I could consider a change?
Thanks in advance.
You can best decide this by forking your current code-base and clone the environment.
Then start with the implementation of the alternative data-store.
You already name certain points you want to look into, so take care of these one after the other.
You will then experience if the way you outlined/prospected the change would actually work or not and with which price that comes.
Keep a worklog in which you write down the steps you do and what your experiences are.
I am building a database of products and manufacturers. I already have the database layout done. I am looking for a simple CRUD class that will let me setup Manufacturers and Products and create the records quickly and easily. I have looked at ORM's but they all seem to be over kill for what I am looking for. Thanks
Take a look at Grocery CRUD, it is easy to use, has nice views with call backs. Might fit your needs. Check it out at http://www.web-and-development.com/grocery_crud/
Look into CakePHP. The code generation (or scaffolding) will get you a working CRUD interface in a few minutes.
I know this question is fairly old, but I came across this jQGrid + PHP component, and for straight out install-and-go simplicity, it's hard to beat.
Hard to say with so few informations...
CouchDB + PHPillow if you don't neccessarily need SQL - works quite nice,
Zend_DB + (Sqlite|MySql|Postgress) otherwise ...
Try Symfony. It's got good performance. Both Symfony and Doctrine (ORM used) have really good documentation sites.
http://www.symfony-project.org/