I started making websites in 1998. Gosh, in the internet years, that’s a forever ago. Remember Perl CGI and its cgi-bin folders? I have also written a lot of website using php along the way, and LAMP stack was sort of my thing for a while. But since I started to focus every efforts on front-end stuff, it have been a while since I looked at simple backends. Some of the sites that I created long ago desparaetly needs some updates. I have, in the past, thought or looked into converting sites to ruby on rails at one point, then looked into python, then thought hard about switching to some kind of static site generator engines (like jekyll or assemble.io), and finally more recently, thought about converting them to MEAN stack. But, really, who has time for that? Lately, I am thinking about just upping my php level and “patcing” it right in php5. Or at least keep the database structure and convert the backends to be more like API or services, still using php.
This weekend, I have been sort of playing with one of my old project: Softball Stats, written by David Carlo. It is an awesome little project.
“SoftballStats is a collection of PHP4 scripts and a MySQL database that track the stats, games, players, and every play made in multiple softball/baseball seasons. SoftballStats also compiles statistics for each player.”
I could use this on my work co-ed softball team, or also use it for my son’s summer league. I started updating it on my github.
Found this excellent website: phpbestpractices.org/
Here ares some notes that I kept while updating some of scripts.
First thing is the way I have been connecting to the database.
I was doing this:
$link = mysql_connect("example.com", "user", "password"); mysql_select_db("database"); $result = mysql_query("SELECT * FROM player WHERE SeasonID = 2014"); $row = mysql_fetch_assoc($result); echo $row['name'];
New (Well, new to me.) way to do this is using PHP Data Object
$pdo = new PDO('mysql:host=example.com;dbname=database', 'user', 'password'); $result = $pdo->query("SELECT * FROM player WHERE SeasonID = 2014"); $row = $result->fetch(PDO::FETCH_ASSOC); echo $row['name'];
Also, way I was doing
mysql_num_rows($result) will now have to changed to
As with mysql_data_seek($result),
Simple enough? I was cruising along, then I encounter the error. Or more like, NOTHING. By default, error is a blank screen, as it turns out.
My php.ini was in
/Applications/MAMP/bin/php/php5.5.10/conf/php.ini (Note that it is not
MAMP/conf as you expect, it’s in
/bin. you can find this infor using . and display_errors was in line 277.
Actually, you need to put those two lines in the php file:
Got some things fixed, but broke more things. Ugh. Still working on it. Ah, time. I wish I had more.
I’ve been posting links that I liked at Posterous (RIP) and then my tumblr blog. Here are a couple weeks worth of links:
- slabText – a jQuery plugin for creating big, bold & responsive headlines
- Doing UX in an Agile World
- MLB – Baseball's confusing and contradictory unwritten rules – ESPN
- csscss by zmoazeni
- Install Bash git completion · bobthecow/git-flow-completion Wiki
- Homebrew — The missing package manager for OS X
- What was that? An Exhibition? We need emotional content.
What was that? An Exhibition? We need emotional content.
I said emotional content, Not anger.
Now try again, with meaning.
Don’t think. Feel!!!!
It is like a finger pointing away to the moon. Don’t concentrate on the finger or you will miss all that heavenly glory. ?
- Mobilefish.com – Base64 encoder and decoder