Lethe Posted March 8, 2009 Share Posted March 8, 2009 Hi, I've just started on PHP after several years on ASP classic (finally!) and I already have about a million unanswered questions running round my head. Here are my first top 4 most important questions for now. The first 3 should be simple enough but the last one is very broad so I'm looking for as much info as I can to point me in the right direction. 1. What are the advantages of using a php odbc connection on a mysql db assuming enterprise level of use and growth? 2. When I do a mysql_connect() I assume it connects to the db only once and not for every mysql_query()? 3. In ASP i'm used to closing recordsets after using them to free up resources. Is there a similar PHP command? 4. Everybody seems to decry the use of eval() and global variables however I can't imagine building a template based website using content stored in a db without them. How do other websites or CMS systems get around this problem? I would like as many examples and reference websites as possible. Your help would be greatly appreciated! Quote Link to comment https://forums.phpfreaks.com/topic/148449-solved-new-to-php/ Share on other sites More sharing options...
trq Posted March 8, 2009 Share Posted March 8, 2009 I too made the move from asp (vbsript) a few years ago now. You wont miss it at all. 1. There are no real advantages to using odbc especially if compared to mysqli. If its a database abstraction layer your looking for, pdo might be of more interest. 2. Your are correct, mysql_connect opens a connection. mysql_query simply uses that connection. 3. There is no need to close resources in php, its all handled (very well) by garbage collection. 4. eval can be dangerous when fed user inputted data. its also notoriously slow. Template engines (IMO) are also a complete waste of resources, they simply add another layer that isn't needed. If you design your application in such a way that your business logic is separated from your application logic you can use php itself as a nice clean, fast templating engine. Quote Link to comment https://forums.phpfreaks.com/topic/148449-solved-new-to-php/#findComment-779403 Share on other sites More sharing options...
Lethe Posted March 8, 2009 Author Share Posted March 8, 2009 Thanks thorpe - thats the first 3 questions answered! But I need more details on the fourth. Ok, I understand what your saying but perhaps what I should have said is that I'm trying to build a php parser. So basically I can inject content anywhere on a template file. I've had this running on ASP for a number of years now with great results and there where no noticeable speed issues. Not only that but it makes everything so clear, simple and reusable. It would amaze me that ASP could actually pull this off better than PHP Also you have to imagine that what I'm create is similar to wordpress in that only certain people would have access to add php code (or whatever) to content. I suppose I could limit those users access to the db unless they had credentials to do so anyway. So that solves that particular security issue. Of course it goes without saying that any sql injection attacks made though the get, post or request would have to be dealt with in the usual way. Am I missing anything? You said "you can use php itself as a nice clean, fast templating engine" - how? Quote Link to comment https://forums.phpfreaks.com/topic/148449-solved-new-to-php/#findComment-779432 Share on other sites More sharing options...
trq Posted March 8, 2009 Share Posted March 8, 2009 You said "you can use php itself as a nice clean, fast templating engine" - how? If you divide your application into three tear's. Model -> View -> Controller. The Model stores your business logic and interacts with your database, the View holds your presentation logic (templates) and the Controller well, controls the application. This is called the MVC design pattern and there should be many examples of it on the net. Good examples of how this works in php are larger frameworks like Zend. With that type of logic in place its easy to have minimal amounts of php within your template files. Creating an entire template syntax is usually overkill and will slow down your application without really adding any benefit to the designer. They still need to learn your template engines syntax, they may as well just learn some basic php and be done with it. Having said that however, if you are still confident that a template engine is the way to go there are already allot of open source projects around that do this. Smarty is one, however I have never, and would never use it. Quote Link to comment https://forums.phpfreaks.com/topic/148449-solved-new-to-php/#findComment-779437 Share on other sites More sharing options...
Lethe Posted March 8, 2009 Author Share Posted March 8, 2009 oops, no sorry, I think the way you and I understand template systems are different I'm not trying to build a template engine like smarty with its own syntax but rather a parser. Something that reads straight php and other content from a db and injects it into a template file. Understand? Now read my last post again up to "Am I missing anything?" Quote Link to comment https://forums.phpfreaks.com/topic/148449-solved-new-to-php/#findComment-779446 Share on other sites More sharing options...
trq Posted March 8, 2009 Share Posted March 8, 2009 Something that reads straight php and other content from a db and injects it into a template file. Understand? In that case you would need to use eval. Though, I seriously think that is a floored design. Why you would need to store code within a database is behond me. Quote Link to comment https://forums.phpfreaks.com/topic/148449-solved-new-to-php/#findComment-779449 Share on other sites More sharing options...
Lethe Posted March 8, 2009 Author Share Posted March 8, 2009 Its just one of things that has bugged me for a long time or maybe I just don't understand the way others have done it. Like I said I had a system on ASP that worked marvelously. But to answer your last question my logic is that it makes sense that content can be stored in a database - forums do it, wordpress do it, and the list goes on and on - so why can't code be considered the same as content. For example go to a page on a website, on that page you get the relevant content from a database and in that content is a bit of code that generates a list of whatever specific to that page. Its the same thing as content right? Anyway - thanks for your time but I think the only way I'm going to solve this mystery is to rip apart joomla, dupral and wordpress. Wish me luck! Quote Link to comment https://forums.phpfreaks.com/topic/148449-solved-new-to-php/#findComment-779473 Share on other sites More sharing options...
trq Posted March 8, 2009 Share Posted March 8, 2009 But to answer your last question my logic is that it makes sense that content can be stored in a database - forums do it, wordpress do it, and the list goes on and on - so why can't code be considered the same as content. There are other way to dynamically load and execute code. Anyway - thanks for your time but I think the only way I'm going to solve this mystery is to rip apart joomla, dupral and wordpress. Wish me luck! Neither of those applications would I consider particularely well designed. Quote Link to comment https://forums.phpfreaks.com/topic/148449-solved-new-to-php/#findComment-779476 Share on other sites More sharing options...
kickstart Posted March 8, 2009 Share Posted March 8, 2009 Hi While I have used eval() to execute user entered commands (basically allowing user entered calculations), it is not an idea I am keen on. Most forums do not allow the entry of php / html, they allow a small subset of formatting commands to be entered as bbcode and then process those into allowable commands (or ignore them if not allowable). All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/148449-solved-new-to-php/#findComment-779477 Share on other sites More sharing options...
RussellReal Posted March 8, 2009 Share Posted March 8, 2009 or, you could store the php code, in a temporary file.. example: <?php $d = mysql_fetch_assoc(mysql_query("SELECT `phpdata` FROM `theTable` WHERE `girls` = 'sexy`")); $newphp = fopen('temp.php','w'); fwrite($newphp,$d['phpdata']); fclose($newphp); ob_start(); include('temp.php'); $evaluatedPHP = ob_get_flush(); unlink('temp.php'); ?> however, eval would be much better lol Quote Link to comment https://forums.phpfreaks.com/topic/148449-solved-new-to-php/#findComment-779478 Share on other sites More sharing options...
Lethe Posted March 8, 2009 Author Share Posted March 8, 2009 There are other way to dynamically load and execute code. You mean something like dumping it in a file and executing it with a include or require? Is there any other ways I don't know about? Quote Link to comment https://forums.phpfreaks.com/topic/148449-solved-new-to-php/#findComment-779480 Share on other sites More sharing options...
trq Posted March 8, 2009 Share Posted March 8, 2009 Theres plenty of ways of dynamically executing code without the need to store it within a database. Really, I can't think of any situation where storing code with a database would be usefull. Quote Link to comment https://forums.phpfreaks.com/topic/148449-solved-new-to-php/#findComment-779491 Share on other sites More sharing options...
Lethe Posted March 8, 2009 Author Share Posted March 8, 2009 Theres plenty of ways of dynamically executing code without the need to store it within a database. Can you tell what ways please? Quote Link to comment https://forums.phpfreaks.com/topic/148449-solved-new-to-php/#findComment-779496 Share on other sites More sharing options...
RussellReal Posted March 8, 2009 Share Posted March 8, 2009 storing it in a file? Quote Link to comment https://forums.phpfreaks.com/topic/148449-solved-new-to-php/#findComment-779501 Share on other sites More sharing options...
trq Posted March 8, 2009 Share Posted March 8, 2009 Theres plenty of ways of dynamically executing code without the need to store it within a database. Can you tell what ways please? The question is far too broad. Maybe you giev us an example of what your trying to do and we might suggest some options. Quote Link to comment https://forums.phpfreaks.com/topic/148449-solved-new-to-php/#findComment-779535 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.