Home » Programming

Checking Type in Python [Guide]

Checking Type in Python

This article explains how to check the type of a variable in the Python programming language. What are Types? The type of a variable determines what it can or can’t do. It determines what value the variable may take and what can be done with that value. Using the type() Function Pass a variable or value to the type() function, and the variable’s type will be returned: myNumber = 4 type(myNumber) # int myString = ‘foo’ type(myString) # str Using the isinstance() Function For more examples, check out the similar isinstance() function: To compare the … Read more

Home » Programming

The MySQL LIMIT and OFFSET Clauses [with Examples]

MySQL LIMIT and OFFSET Clauses

This tutorial covers limiting the number of results from a MySQL database query using the LIMIT clause and skipping results using the OFFSET clause. This is especially useful when wanting to paginate results in web applications – spreading them out over several pages by retrieving a subset of the database results. Examples Examples will use the following table and data: table_people id name 1 Bob 2 Ted 3 Jim 4 Pip 5 Zak 6 Tim LIMIT Here’s how to limit the results to 2 records using LIMIT: SELECT * FROM table_people LIMIT … Read more

Home » Programming

MySQL CASE Statement and CASE Operator – Difference and Examples

MySQL CASE Statement and CASE Operator

There are two things called CASE in MySQL (and, by extension, the compatible MariaDB). The CASE Operator, for use in queries. The CASE Statement, for use in stored programs and procedures. Both have similar syntax and the same purpose. Both MySQL CASE Operator and Statement provide control over the results based on a set of conditions. Examples in this article will use the following test data: table_people id name 1 Bob 2 Ted 3 Jim 4 Pip 5 Zak 6 Tim CASE Operator The CASE operator is used … Read more

Home » Programming

Showing Errors in PHP [Tutorial]

Showing Errors in PHP

This tutorial explains how to use several methods for displaying errors in a PHP application for debugging purposes. Be Careful There are security considerations when displaying errors in any application. Be careful when and where errors are displayed – especially when building products for the web – as the errors may contain sensitive information. For example, if an application connects to a database and the database crashes, an error will be produced. That error may contain the username and password used to connect to the database. If … Read more

Categories PHP

Home » Programming

Add Days (or Minutes, or Hours) to Javascript Date [or Subtract]

Add Days to Javascript Date

This article will explain how to add (or subtract) days, minutes, hours, seconds (etc.) to a JavaScript date. Why would you want to do this? Perhaps you want to tell a user that their assignment is due in a week and provide the date, or maybe your application needs to know what the date was 30 days ago to pop up a reminder – there are near-infinite usage cases. Add Days to Date Using Vanilla JavaScript First, here’s how it’s done in plain old JavaScript: … Read more

Home » Programming

MySQL vs MariaDB vs MongoDB vs PostgreSQL vs SQLite vs MS SQL – Which to Choose?

Which database to Choose

There is a lot of weird-sounding language around databases. Most of it centers on the names of the popular database software which is available. It can make it tough to choose. Each strangely named database solution offers features making it suitable for different tasks. This article should shed some light on what’s what. SQL Is a Language SQL (pronounced ESS-QUE-ELL or sequel depending on which side of the raging debate you side with). It stands for Structured Query Language. It is not a piece of software – it’s the … Read more

Home » Programming

6 Best PHP Frameworks to Consider in 2021

Best PHP Frameworks

PHP frameworks speed up the development of complex applications greatly. This article features 6 of the most popular frameworks to consider in 2021. These frameworks provide varying scaffolding levels to get you started, from database operations, object handling, user authentication, and page templating. So you are free to build your application without having to constantly write and re-write the common functions that make your application work. They also come with some security benefits – using a sanitized database abstraction layer that has been written and … Read more

Categories PHP

Home » Programming

PHP shell_exec Function: How to Use It [With Examples]

PHP shell exec Function

This tutorial explains how to use the shell_exec function in PHP in order to execute code via the shell and return the output as a string. PHP is a versatile programming language for building server-side web applications, but sometimes you need to execute code from another environment and use the result in PHP. This can be achieved by using the shell_exec function to execute commands on the system’s shell hosting your PHP code and return the result as a string to PHP. When doing so, there are security … Read more

Categories PHP

Home » Programming

Javascript eval() Function (and Why to NEVER Use It)

Javascript eval Function

The JavaScript eval() function executes a string as JavaScript. This is a massive security risk as, if used in production, it can allow third parties to execute their own code in your app. eval() Syntax eval(string) Note that: string is a string that contains JavaScript Code eval() will return the value returned by executing the code in the string Just don’t use it Example of Javascript eval() This article gets one example only so you can see how eval() works, so that if you accidentally fall on your keyboard and the … Read more

Home » Programming

Python Main Function & Method: What Is It and How Is It Used?

Python Main Function Method

As you build more complex Python apps, you will probably want to start splitting your code into separate files. What Is the __main__ Function? Importing and executing code from another file is common in even small scripts and apps built with Python. As your library of scripts increases, you may choose to import previously written code into new projects. The __main__ function in Python is only executed when the script is called directly, allowing you to set different behavior based on how your code is being … Read more