Archive | Others RSS feed for this section

How To Change Multiple MySQL Tables’ Collation At Once In Bulk

Using PHPMyAdmin to change table collations is a tedious task because you have to change each table one-by-one. In order to change ALL the tables’ collations at once, you’ll need to use a PHP script to help you. The following code does the trick: 1 2 3 4 5 6 7 8 9 10 11 [...]

Continue reading...

How To Protect Your Websites Against SQL Injection Attacks

How To Protect Your Websites Against SQL Injection Attacks

If not protected properly, websites can be vulnerable to SQL injection attacks. A layered approach to thwart SQL injection attacks provides a good defense. The following provide just some ways that you can adopt to start protecting your websites. 1. Sanitize the input The first thing you need to do is to make sure that [...]

Continue reading...

How To Remove The Last Character in a String

How To Remove The Last Character in a String

To remove the last character (or the last X characters) of a string, just use PHP’s substr_replace() function. Basically, you just need to tell the function to replace the last character of a string (or the last X characters) with nothing. Here’s a code sample: $old_string = “One, Two, Three,”; // remove the last comma [...]

Continue reading...

How To Process Multiple SQL Statements

How To Process Multiple SQL Statements

Sometimes you’ll find yourself needing to execute multiple statements at once. The normal mysql() class only allows for single statements, but the recent mysqli() offers this functionality. To use it, follow this code example:

Continue reading...

How To Split Comma-separated Values

How To Split Comma-separated Values

To split a string that contains values separated by commas (comma-separated values), what you need is the PHP explode() function. Here’s a code example on how to use the explode() function: $cake = “slice1,slice2,slice3,slice4″; $slices = explode(“,”, $cake); echo $slices[0]; // slice1 echo $slices[1]; // slice2 And if you have a space after your comma, [...]

Continue reading...

Best CodeIgniter Web Hosting

Best CodeIgniter Web Hosting

Unlike other PHP frameworks, CodeIgniter has a very light footprint and is more flexible in terms of web hosting requirements. As a result, CodeIgniter allows you to run off pretty much any standard PHP hosting package (running off either Linux or Windows). The only thing that you should consider is then your own site’s traffic [...]

Continue reading...

How To Customise URLs and Create SEO-Friendly URLs in CodeIgniter

How To Customise URLs and Create SEO-Friendly URLs in CodeIgniter

CodeIgniter, the PHP framework, allows for URL customization so that the URLs are more friendly to search engines. As a rule of thumb when you deal with URLs, it is best to avoid long URLs. To shorten your CodeIgniter URLs, for e.g. changing the default controller/method format in the URLs to just reflect the method [...]

Continue reading...

How To Store Arrays In MySQL / PHP

How To Store Arrays In MySQL / PHP

Arrays are the best tool in the PHP language if you’re dealing with associative data. However, it’s one thing to be manipulating arrays, but what if you need to store the entire array in a database? Structuring your database table so that you don’t have to store entire arrays should be your first priority, but [...]

Continue reading...

How To Fill a HTML Dropdown With Database Results in Code Igniter

How To Fill a HTML Dropdown With Database Results in Code Igniter

In Code Igniter, you can retrieve database results and format the data so that it appears in a HTML dropdown list automatically. Here’s how to do this: First, you’ll need to edit your model class. Here, you’ll see that we have a method named “get_dropdown()” that will basically query our database table for a set [...]

Continue reading...

Difference Between Row, Result, and Result_array in CodeIgniter

Difference Between Row, Result, and Result_array in CodeIgniter

There are 3 methods that allow you to retrieve data from a database within CodeIgniter: row(), result(), and result_array(). However, there’s a difference as to how you should reference the values that you obtain with these methods, as row() and result() return objects, but result_array() returns an array. Here’s a typical example of how you [...]

Continue reading...