PHP Display errors & Debug

To turn on error reporting

1. Set in php.ini

display_errors = On;
error_reporting = E_ALL;

2. In php.code

//If PHP config doesn't have error_reporting enabled, simply enable it at the top of your script:
ini_set('display_errors', 1);

//error_reporting sets which PHP errors are reported
error_reporting(E_ALL);

Check error logs on apache server

Check errors in log file that is configured in etc/apache2/httpd.conf

DEBUG

Php useful debugging functions

gettype($variable) – Get variable type;

var_dump($variable) – Dumps information about a variable;
With var_dump You can print false because var_dump is printing both the type and the value.

$var = FALSE;
print($var);
//it shows nothing

$var = FALSE;
var_dump($var);
//bool(false)

get_defined_vars() – Return an array of all defined variables;

debug_backtrace() – show backtrace

var_dump(debug_backtrace());

Tools

Xdebug

Firebug

Examples of errors

MySQL Error “Incorrect integer value “for column ‘name’ at row 1”

This error appear because mysql attempting to insert or update a row with the integer entry taking the default value 0 or NULL.

MySQL return this error because SQL_MODE is set in STRICT mode.

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

To find this setting you must go to phpmyadmin -> Information schema -> Global variables -> sort them downwards by the variable names and at pag 2 will find sql_mode.

To resolve this issue have to remove STRICT_TRANS_TABLES or set SQL_MODE to an empty string, sql_mode=””

After this change you should restart MySQL.

Hello there!

I hope you find this post useful!

I'm Mihai, an online marketing specialist, very passionate about everything that means online marketing, focused on eCommerce.

If you have a collaboration proposal or need helps with your projects feel free to contact me. I will always be glad to help you!

Leave a Reply

Your email address will not be published. Required fields are marked *