Archive for the ‘mysql’ Category

php grab bag: more stepping stones for project X

December 15, 2005

Here’s one that we’ve come across before, and used before, and yet we had to learn this little business again: addslashes(). Use addslashes when you want your forms to take in whatever a user inputs to your forms. We used this previously to help thwart hacker attacks — using addslashes prevents users from inputting SQL code into your forms and screwing up your databases. Anyway, Harry Feucks makes a strong point about using addslashes vs. magic quotes.

We used a handy bit of a hack from A List Apart for aligning a form without tables, aligning a form with CSS using cross-floats and such.

We found some offhand PHP tutorials at tizag helpful this time around. They have an interesting argument for ASP v. PHP, though we have used both and find PHP to be perfectly great and robust for any size project. We also found their MySQL tutorials helpful as well.

Lastly, we have had some code examples from PHP freaks on our desktop for a while. We haven;t tried any of them, but we wanted to make sure they were noted before the links went away. There is their PHP hit counter. Their expanding and collapsing menus look interested (and might be helpful in another project where Eric Meyer’s menus don;t seem to be cutting the muster). And then there is their PHP calendar, though we have been loving PHP iCalendar (except for a few small bits we’d rather not get into right now).

MySQL / PHP handy reference

December 6, 2005

We work a lot with MySQL and PHP. WEll, not as much as we’d like, but we are learning. And we are getting better. But in the mean time, we use a lot of references, including many online ones. Here are some handy things we recently came across to help us with a trouble ticket application we are building, some of which is embarrasingly simple and basic, but it helps to write it out:

MySQL manual on INSERT.

A very nicely laid out set of things you can do with your records from the Institute for Information Systems and and Computer Media. Includes some easy examples.

FAQTS has some good PHP FAQs going, including this nice reminder on how to access the last record in a table. Note: the queries on this page have a type. It should read “mysql_query” instead of what’s lsited.

Computing dot net helped clarify that  one should use mysql_num_rows, and not mysql_numrows.

We learned a bit about the necessity of using mysql_fetch_row for this early part of the project. PHP Addict helped us crack through the maddness in their help forum. The good folks at Zend (the PHP folks themselves) had many good examples for it. But it was Larry Ullman (whose PeachPit books are nice) who empahsized that it (or something like it) is always needed: “What you are printing is just a resource ID. You ALWAYS have to use mysql_fetch_array() to access the actual returned information“. For good measure, here is the PHP manual entry on mysql_fetch_array().