php

recent posts related to the php programming language

Use the PHP addslashes function to fix SQL INSERT problems

PHP MySQL FAQ: Can you share an example of how to use the PHP addslashes function when creating a SQL INSERT statement?

When you're inserting records into a database table with plain PHP (as opposed to using a PHP framework), some of the fields you're inserting may have characters in them that will cause problems during the SQL INSERT process. Characters that will cause problems on database INSERT statements include the single quote, double quote, backslash, and NUL characters.

A CakePHP debug strategy

I just started working with CakePHP in the last two weeks, and as a newbie, I've found a simple debug strategy that I like. I've used this CakePHP debug technique several times when trying to formulate a CakePHP find query.

CakePHP find - a SQL limit query example (SQL select with limit clause)

When working with CakePHP, one of the hardest things for me has been getting used to formulating SQL queries with the CakePHP find method syntax. Today I needed to run a SQL query where I limited the amount of records returned from the database, and after a little trial and error, I found the correct CakePHP SQL LIMIT syntax, and thought I'd share that here today.

The CakePHP error log (CakePHP error logging)

CakePHP error log FAQ: Where is the CakePHP error log, and how do I write to it?

CakePHP error log file location

The CakePHP error log file is named error.log, and it is located in the $app/tmp/logs directory of your CakePHP application:

$app/tmp/logs/error.log

(Where $app represents the name of your CakePHP application.)

CakePHP find distinct - SELECT DISTINCT syntax for the CakePHP find method

As a CakePHP newbie, I'm spending a lot of time learning how to formulate SQL queries with the CakePHP find function syntax. This morning I need to create a "select distinct" SQL query in CakePHP. Fortunately this wasn't too hard once I figured out how to piece it all together.

In my case, I have a database table named logfile_records, and I wanted to run a SQL "select distinct" query against that table. If I was going to write the query in plain SQL I'd write it like this:

The PHP Base64 encode and decode functions

PHP FAQ: Can you share an example of the PHP Base64 encode and decode functions?

Every once in a while when you're working on a web application you'll run into data that can cause you some problems, and when that happens, the PHP base64_encode function can come to your rescue. Here's a quick look at a problem I ran into yesterday using CakePHP, and how the PHP base64_encode and base64_decode functions helped me encode a URL (URI) and bail me out of my predicament.

CakePHP SQL query - How to run a SQL database query in CakePHP

CakePHP SQL query FAQ: How can I run a standard SQL query in CakePHP?

MAMP - Mac OS X, Apache, MySQL, and PHP (and CakePHP too)

PHP LAMP Mac FAQ: Can you recommend a good way to develop Mac PHP/LAMP applications on Mac OS X?

PHP modulus operator example

PHP FAQ: Can you share an example of how to use the PHP modulus operator?

Sure, here are two examples of how to use the PHP modulus operator. In this first example, because the remainder (the modulus, or technically, the modulo) of 100 divided by 5 is zero, the string "a was 0" will be printed:

PHP installation error - unable to install php5 - configure: error: libjpeg.(a|so) not found

I ran into this error message today when trying to install PHP 5.2.x on a CentOS Linux server:

unable to install php5 - configure: error: libjpeg.(a|so) not found.

Actually, although I wrote "install" above, I was trying to run the PHP configure script when I got that PHP error message. (configure is the command you run before you run the make or make install commands.)

Syndicate content