You know those stupid little things you come accross after years in the profession, that make you say "Golly, if I'd just known that 3 or 4 years ago, it would have saved a ton
of work!" This is one of them.
I ran one of my database front-ends that worked great in PHP3, under PHP4 and found that back-slashes started poping up like rabbits on fertility hormones. After a little
research into the problem, I found out what it was: mysql_escape_string, a function not availble in PHP3 was implemented "transparently" in PHP4 and (unfortunately) was
installed "backwards": It escapes the result set, which is not how string escaping was intended. The fix: I've made a fix called mysql_unescape_string. You won't find an analog
of it at www.mysql.com because its a bastard function specifically for taking care of the PHP4 implementation problem. See the example section for usage of it... (Also, see the
"mysql_escape_string" function in this same section for my original fix for string escaping in MySQL)
This selection of PHP files will allow you to implement a "member's only" area in your web site, complete with recognizing re-entering members and new member form. Uses MySQL
back-end.
What is the most common way to access data in the world today? If pressed for this answer, I would have to say it is Microsoft DAO (a.k.a. Data Access Object) whether it be with
a VB, Access or VC++ front-end or with an Access or enterprise-level back-end. The greatest single group of application programmers use DAO, period. This first stab at providing
the most important parts of DAO (i.e. those that are use about 90% of the time) is my hope that many ASP programmers, sickened by Microsoft's insistance that web-based
programming be done with the cumbersome, twitchy, and many times over-complicated ADO (ActiveX Data Object) may turn to PHP and MySQL without having to relearn a different data
access methodology. There are some important things missing in this first release. Recordset objects don't have the old "edit/update" functionality, and in this first release
don't even have a findfirst/findnext method (but it is coming). But even with all the missing pieces, this release allows you to do everything you need to: query the database,
execute SQL commands, traverse recordsets, object-based approaches. AND its available by including just one small file at the top of every PHP script you write. Email me with
your thoughts people! I'll get to it faster if there is a need out there!
This is a function that backs up the structure and data of a MySQL database and represents them as a large text file of SQL statements. Doesn't require special disk access
permissions, it pulls everything through the connection handle itself. Output can be sent transfered via FTP (i.e. by transfering the text file) or by HTTP (i.e. by direct
output to the invoking browser).
New and Improved! New function mysql_cvdate allows you to take a form-entered date value and express it in mysql's SQL date format. Also includes some real-life functions you
can call to perform common date/time conversions between MySQL datetime format, MySQL timestamp format and UNIX timestamp (i.e. seconds after epoch) with "human" output. Time
left function perfect for auction scripts, or where you need output of the difference between two supplied times.
Someone wanted to have a converter that took a "human" time and converted it to a MySQL timestamp. Use the function cvdate() to convert to a UNIX time stamp, then use
timestamp_to_mysql() (fount in the original mysql date/time converters article) to get the MySQL timestamp value. (Also check out strtotime() for a good english to timestamp
converter!)
Someone wanted to have a converter that took a "human" time and converted it to a MySQL timestamp. Use the function cvdate() to convert to a UNIX time stamp, then use
timestamp_to_mysql() (fount in the original mysql date/time converters article) to get the MySQL timestamp value. (Also check out strtotime() for a good english to timestamp
converter!)
This is the easiest way I know how to get data from a MySQL database to and Microsoft Access database. Its not automatic, but its by far the best way to move tables from MySQL
to Access. A single function generates a CSV file (with Access string escaping) that can be easily downloaded and "imported" into Access.
A big hole in PHP's mysql support: the lack of mysql_escape_string function. Wondered what the easiest way of taking any zero-terminated string (i.e. one with single/double
quotes, commas, special chars) and putting it in an SQL statement so it ALWAYS WORKS? Use this version of mysql_escape_string; based on the formal MySQL escape charater
definition found at www.mysql.com.
This function returns the price to send a standard Priority Mail package from one zip code to another zip code, based on weight. No USPS-issued username or password is required.
Safety feature. Error repression.
PHP is great for a lot of things, but report generation is NOT one of them (compared to Crystal Reports or other report generators). I really like Microsoft Access's report
environment, but its a royal pain in the butt to tranfer data from a MySQL database to Access, especially if you need to do it multiple times (like you have to with real life
reports). Here is the simplest way I know how to do it FULLY AUTOMATICALLY.