On Jan 22, 2008 8:44 AM, Jason Pruim <japruim@xxxxxxxxxx> wrote: > > On Jan 21, 2008, at 4:14 PM, Dave Goodchild wrote: > > > Don't be scared of functions, no magic or mystery there, all you are > > doing > > is putting your code in a function like so: > > > > function add($a, $b) { > > return $a + $b; > > } > > > > ..for example and calling it like so: > > > > $a = 12; > > $b = 100; > > $sum = add(12, 13); > > > > ...etc etc, not too much more to learn than that and now I can call > > add() in > > many places... > > > So all I have to do (At least to really simplify what I'm sure they > can do) is put the code I want to execute into the function and then > just list the variables as arguments? Such as: > > function dbconnect ($host, $user, $pass, $database) { > mysqli_connect($host, $user, $pass, $database); > etc. etc. > > } > > Or something like that? > > And then I can simply call my dbconnect() anywhere I might need to > connect to a database? Or a different database? > > > > -- > > Jason Pruim > Raoset Inc. > Technology Manager > MQC Specialist > 3251 132nd ave > Holland, MI, 49424 > www.raoset.com > japruim@xxxxxxxxxx > > > That is basically it. You're going to want to learn the why, not just the how though. There is a reason for creating functions and it isn't just code reuse. Think about when you want to change your export script. Say you needed to add a field to it. Right now you have to edit some web facing php script mixed with code that handles the request and connects to your database. Wouldn't it be easier if you just could edit a very specific spot that was easy to get to and pop a column on to that instead of sifting through dozens of if statements? Of course the best way to learn is by doing things. So keep on writing stuff and try to keep moving forward judging how you could improve on the design along the way. Please read about programming theory and why you do things. It will save you more time in the end. Another good thing you could do is download some reputable open source projects and look at how they wrote the code and learn from that. And finally make sure that learning about web security is a big part of your growth from day one. Don't wait until you've wrote tons of sites to realize that your code is riddled with XSS & sql injection. Here is a starting point: http://talks.php.net/index.php/Security Here is a list of some you might look at: http://drupal.org/ http://fudforum.org/ http://s9y.org/ Stay away from Wordpress and phpBB. =) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php