PHP Best Practices & Notes
The following notes are listed for reference to PHP development.
MySql Query Example
// mysql_query(“SELECT * FROM searchengine WHERE keywords LIKE ‘%mike%’ OR keywords LIKE ‘%stratton%'”);
PHP Safe Mode is deprecated.
The following php script can test the connection to your database.
Create a php file with the following code and save as test.php. Upload to your web server and run the script from a browser.
$host = ‘localhost’;
$user = ‘joomla_user;
$db = ‘joomla_db’;
//Don’t change below here
= mysql_connect($host, $user, $pass);
‘<hr />anything above this linebreak is BAD!’;
XAMPP / WAMP
After installing XAMPP start MySql and Apache.
In your browser type in "localhost"
On the left click on "Security"
Make sure all tabs are green or yellow, except for running PHP in safe mode.
This should be red and stay red. PHP safe mode is deprecated as of PHP 5.3.0
After an install of XAMPP, creation of all sites and files should be saved in
the mycomputer\xampp\htdocs directory. If you open localhost in your browser you
will note that your url is entitled http://localhost/xampp This url is actually
pointing to the mycomputer\xampp\htdocs directory. To simplify, create a new
folder entitled "php_sandbox". Save this folder here: mycomputer\xampp\htdocs\php_sandbox.
Then type the following url into your browser: http://localhost/php_sandbox.
Your browser will list all files and subfolders within the mycomputer\xampp\htdocs\php_sandbox
During development of PHP, it is best that all errors are displayed. To test
if errors are turned on, type in the following code into a .php file, and then
run from within your localhost.
<?php phpinfo(); ?>
Note: Do not use this on a live site, as it is a security risk.
After running this file, it should display PHP configuration information.
Scroll down to the box entitled "Configuration PHP Core". Note that line that
says "display_errors". This line should be turned "on". If it is not follow
1. Locate the php.ini file from the following directory: mycomputer\xampp\php\php.ini
2. Open the php.ini file with notepad or similar text editor. DO NOT USE a word
processor to open the php.ini file.
3. Scroll down and Locate the "; Error handling and logging ;" section.
4. After locating the "Error handling and logging" section, Slowly scroll down
and find the following line: error_reporting = E_ALL & ~E_NOTICE
5. Comment out the "error_reporting = E_ALL & ~E_NOTICE" line.
6. Copy and paste the "error_reporting = E_ALL & ~E_NOTICE" below the commented
7. Uncomment the new line and edit so that it says: "error_reporting = E_ALL"
8. Save and close php.ini file.
9. Run the <?php phpinfo(); ?> script.
10. Verify that errors are being displayed.
11. Upon completion, Eat a taco.