Home » PHP/MySQL

In this tutorial, learn about the get_browser() PHP function and its configuration. We’ll learn how to use Gary Keith’s browser information database (browscap.ini) with the PHP browscap directive. I wanted one of my web applications to have a different appearance on mobile phones and devices. I didn’t really want to set up an entirely...
Often we search for records in a database table for fetching records that were created or modified on a particular date or between two dates. We match against a date field and add multiple conditions to find records with a date field value ranging between two dates. It would look something like this: Select * from tables where CREATE_TIME >= "2007-03-14...
When we need to swap the values of two variables, we use a third variable temporarily to hold the data between swapping.  Something like this: <?php $tmp = $a; $a = $b; $b = $tmp; ?> Here is another way without using a temp or a third variable. <?php list($b, $a) = array($a, $b); ?> And if you want to make it a function: <?php function...
The Auth Component in CakePHP redirects the user to the log-in page when a user tries to access any protected pages in the application. The default log-in page is set by defining the loginAction variable in the beforeFilter function in your UsersController or AppController. But if you have used plug-ins in your application, and if a user tries to access...
A very basic tutorial. For the beginners who want to pass array values from PHP to Javascript for them to be accessible in the client side JS as an array. It’s really easy to pass PHP array to Javascript. The below code passes a string array in PHP to Javascript. <?php $arr = array("a","b","c"); ?> <script> var...
Sometimes, or very rarely we might need to access a model in AppController (Application Controller). This could be for fetching values from a table and make it available for all the controllers in the application (AppController is inherited by all the other controllers). Also, often we need to access models that are not associated with a controller. I...
Filed in: CakePHP, PHP/MySQL
One of the most powerful features of CakePHP is the ability to link relational mapping provided by the model. In CakePHP, the links between models are handled through associations. The associations are defined in the models as hasOne, hasMany, belongsTo etc. It is possible to define deep relationships involving many tables and retrieve data. But CakePHP...
Filed in: CakePHP, PHP/MySQL
Developers normally use functions that use Regular Expression to convert under_scored strings in to CamelCased strings. Usage of Regular Expression is quite heavy. We can use a simple yet powerful method to convert these strings to CamelCase without using RegEx in PHP. Here is the method: echo join(””, array_map(“ucwords”, explode(‘_’,...
Do you think your website is sluggish? Does it take a lot of time to download on to a user computer? Here are some techniques to make your site load faster on user computers and enhance it’s performance. These are some of the best practices followed in the Web industry. Implementing these practices has proved that your site will become 20-30%...
Failed To Read Auto-Increment Value From Storage Engine Error in MySQL. This is a very strange MySQL error. The error happens when trying to insert a new row in to a table. Basically this is a bug in MySQL that causes the problem but a work around is simple. The problem happens when the Auto-Increment value of a table grows beyond the limit. Just run...
Filed in: PHP/MySQL

Page optimized by WP Minify WordPress Plugin