DC Web Makers Blog17

Blog & News Details

Five Tools That Any Serious PHP Programmer Must Know

  • Posted: Monday April 8th
  • PHP is a dominant programming language in the area of website and mobile App developments. Although there are many books and contents dedicated to PHP, there is no concise survey of all essential tools that a professional PHP programmer should possess. After years of developing and improving many large-scale websites, mobile Apps, and custom social sites in many languages. especially PHP, I got motivated to share this article with other developers. Specifically, here are five tools that any serious PHP programmers must know:

    I. Lovely Arrays
    When it comes to arrays and PHP array functions, the sky is your limit. I have developed many complex algorithms by using lovely PHP array functions. Indeed, the more you use them, the more you like them. There are three types of arrays: anonymous, indexed, and associate. My ten favorite array functions are: array_merge, array_filter, array_unique, array_push, array_key_exists, is_array, in_array, array_sum, array_rand, array_count_values

    II. Loop The Loop
    I have not seen any PHP project without a loop. I use "while" or "do while" loops mostly in conjunction with database queries, "foreach " for arrays, and "for" loop for all other scripts. However, I found the "for" loop as the most flexible and handy tool.

    III. Custom Functions
    As a rule of thumb, if you are going to use the same script in more than three pages, you would be better off creating a custom function for it. Your custom function does not need to have return value. Make sure to have a separate folder on your project root directory for your custom functions.

    IV. Global Friends
    There are four PHP global variables (or arrays) that I use a lot: $_SESSION, $_GET, $_POST, and S_SERVER. To unload your server, make sure to unset or destroy the session after certain hours of user inactivity.

    V. PHP-MySQL Functions
    Below are the ten essential PHP-MySQL functions:
    - mysql_connect(): to connect to the database(db)
    - mysql_select_db()- to select the db
    - mysqli_fetch_assoc() or mysql_fetch_array(): to fetch data from db table
    - mysqli_num_rows(): to count the number of results (or rows) in the query result set
    - mysqli_error(): to return the error
    - mysqli_query($dcwebmakers_company,): to make queries (INSERT, DELETE, UPDATE, or SELECT)
    - mysqli_real_escape_string($dcwebmakers_company,): to sanitize the values
    - mysqli_insert_id(): to return the table primary key of the last insertion
    - mysqli_free_result(): to free-up the result set
    - mysqli_affected_rows(): to return the number of affected rows in last insertion or update

    No matter how advance will be your next project, having resources to these five tools will walk you through the project delivery.