Learnit Training
« Back to all themes

Trainings PHP

We have developed several PHP training courses in which you can learn everything about programming in PHP. Among others, our course PHP basic and for the more advanced programmers we have the course PHP advanced.

link]

Top 10 most popular programming languages

At the end of last year, a list of the most popular programming languages of 2020 was announced. Not entirely surprisingly, as ultimate favourite, C was still on top of TIOBE's index. This year, Python did manage to surprise us: for the first time in history, Python overtook Java and we find Python on place 2 and Java on place 3 in the top 10. Besides Python, also R, Perl and Go are gaining popularity. R even ended surprisingly on place 9 in the top 10 list; TIOBE has therefore labelled R as 'programming language of the year 2020'.

Why is Python gaining popularity?

The CEO of TIOBE's INDEX Paul Jansen said about Python catching up with Java: "Some time ago I had a flat tire and called the road patrol to help me out. The mechanic asked about my living and when I used the word 'software' in my answer, he smiled and started talking very enthusiastically about his own passion: programming in Python. From that moment on, I knew Python would become ubiquitous." Whereas ten years ago it was mainly software engineers who were concerned with the various programming languages, nowadays you see that more and more people on the shop floor have programming skills. This has everything to do with the fact that there is a shortage of classical programmers. Moreover, a programming language such as Python is relatively easy to use when you want to work with large quantities of data. Would you like to work with data yourself, but do you have little or no knowledge of a programming language? Then take a look at our courses Python programming basics or Python for data analysis. Do you already have a fair knowledge of Python? Then the course Python programming continuation course is really something for you!

Why is 'R' gaining popularity?

Big data is a term that most people undoubtedly hear more than once. Programmes such as R are perfect for converting these so-called big data into useful information for organisations, and R is also a lot easier to use than a language such as 'C'. For example, did you know that R is one of the programming languages that was used to find a COVID-19 vaccine? In addition, you can see that universities and colleges are increasingly exchanging static programmes such as Stata, SAS and SPSS for static programming languages such as R. Professional groups in which many static analyses occur are also increasingly using R. Think for example of data analysts, mathematicians, econometricians but also marketers. The advantage of a programme like R is that it costs nothing: it is an 'open source' project, which anyone can use and improve. In addition, R is known for the fact that you can easily visualise data with packages such as 'ggplot2', with which you can make a graph, for example.

link]

You can learn to program!

Visit any job site and you will see it immediately: there is an unprecedented demand for programmers. If you are looking for a well-paid job with excellent future prospects, then learning to program is a must. Even for jobs where you do not program yourself, a programming language is an excellent addition to your CV. However, there are countless programming languages, so where is the best place to start? And which languages are interesting for the future? We made an overview of the 10 most important programming languages. Languages in which you can also receive training immediately: let those jobs come!

Java

Java was the most popular programming language for employers for many years. Although it has recently been surpassed by SQL, it is still very popular. Java is the standard for many enterprise software, is used by more than 9 million developers and is used to control more than 7 billion (!) devices worldwide. The programming language owes its popularity mainly to the simplicity and readability of the code, which makes it a good starting point for beginning programmers. Also, one of Java's basic principles is compatibility, which ensures that older applications continue to work.

SQL

You will find SQL everywhere. Database technologies such as MySQL, PostgreSQL and MicrosoftSQL keep banks, universities, hospitals, small and large companies up and running. It is no exaggeration to say that every computer and person with access to technology has come into contact with SQL in one way or another. For example, iOS and Android devices have access to SQLite, an SQL database, and there are countless mobile applications that use SQL directly.

C

C dates back to the early 1970s, when it was developed as a generic programming language. As one of the oldest programming languages in existence, C provides the building blocks for other popular languages such as C++, Java, Javascript and Python. C itself is mainly used for operating systems and industrial applications.

C++

C is an object-oriented programming language based on C. Since the language was developed in the 1980s, it has been used to develop Adobe and Microsoft applications, MongoDB databases and large parts of Mac OS/X operating system. It is considered by many to be the best programming language to learn for applications where performance is of great importance, such as games or audio/video editing.

iOS / Objective C / Swift

Until 2014, Objective C was the programming language used by the Apple operating system. It plays a role in Apple's OS X, iOS and its APIs. For a long time it was the language in which you as a programmer had to write iPhone applications, until Apple came up with its own programming language a few years ago: Swift. Swift is very similar in many ways to C++ and its predecessor Objective C, but is a little easier to learn for most programmers.

Javascript

Javascript - not to be confused with Java - is widely used to add interactivity to websites and is supported by all major internet browsers. Not only can it be used for simple functionality such as pop-ups or simple games, it also forms the basis for Node.js - a server technology widely used in real-time communication.

PHP

PHP was actually never intended to be a programming language. Danish-Canadian programmer Rasmus Lerdorf developed PHP in 1994 as a set of tools that enabled him to manage his personal website (Personal HomePage). Today, the meaning of the abbreviation has changed to Hypertest Pre-Processor and the language is used on servers to generate HTML websites dynamically. PHP is easy to learn, but has many advanced features that are of great value to experienced programmers.

HTML / CSS

HTML forms the basis for web pages. The programming language does this by basically laying down a structure that can be extended or adapted by other languages. For example, Javascript can be used to add advanced interactivity and CSS influences the presentation, formatting and layout of web pages. Although PHP can generate HTML from a server, knowledge of HTML and CSS is an absolute must for web developers.

Python

Python is a server-side programming language for websites and mobile applications. It is a relatively easy language to learn, thanks to the readability and conciseness of the code. In Python, it is often possible to express a concept in fewer lines than in many other languages. Python is used in applications such as Instagram and Pinterest in the form of the Django web framework. Google, Yahoo! and NASA all use Python.

Ruby

Ruby is - like Python - a programming language that is very user-friendly for beginning programmers. At the same time, the object-oriented language is very dynamic and therefore popular for developing websites and mobile apps. It is the basis of the Ruby on Rails framework used by Groupon, Shopify, Scribd and GitHub.

Complete the list!

Of course, there are many more programming languages. We have listed just a few of the most popular ones for you. Do you have any additions? Are you missing a language that you use really often? Share your knowledge and experience with us!

Want to learn a programming language?

Do you want to learn a (different) programming language? Then quickly discover our workshops and courses. Under the guidance of an experienced trainer, you will learn the basics of programming in an efficient manner. Are you a bit further on? Then it is possible to register for an advanced training. You will then go deeper into the subject matter. Such a training course is not only fun, but it is also closely linked to practice. That way, you know for sure that you can put your new knowledge and skills into practice immediately!

link]

Export SQL database to CSV

PHP allows you to easily present information from your database to your visitors in a CSV file. CSV (Comma Separated Values) is a simple format where all values are separated by a comma. It can be opened with Excel, for example, after which you can use it for data analysis or to create graphs.

We are going to write a PHP script here that retrieves results from our database and puts them in a CSV file. In our case, the results of course exams.

The first step is to retrieve the data from the database. For this, we use PDO(5 reasons for using PDO with SQL databases).

$db_user = 'learnit';
$db_pass = 'geheim';
$db_name = 'uitslagen';
$db_host = 'localhost';

try {
    $db = new PDO("mysql:host=$db_host;dbname=$db_name;charset=utf8", 
                  $db_user, 
                  $db_pass, 
                  // Als een error optreed moet PDO een exception gooien
                  array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
	$query = "SELECT id, naam, email, resultaat FROM Uitslagen";
	$pds = $db->query($query); 
} catch(PDOException $ex) {
    echo "An Error occured: " . $ex->getMessage(); 
	exit();
}	

We use a try-catch here to catch exceptions that may occur with a connection problem. The result of the query is a PDOStatement Object. We can retrieve the records from here, but first we need to make some preparations:

header('Content-Type: text/csv' );
header('Content-Disposition: attachment; filename="results.csv");

With the help of the header function we modify the HTTP header. We want the visitor to be able to download the file directly. We do this by specifying in the header that it is a CSV file and that it is called "results.csv".

Now that we have opened the standard output, we can start writing the CSV file itself:

$fp = fopen('php://output', 'w');
fputs($fp, chr(0xEF) . chr(0xBB) . chr(0xBF));

In the CSV file we want to use the UTF-8 encoding. To ensure that Excel recognises that this is a UTF-8 encoding, the CSV file must start with 0xEF,0xBB,0xBF.

Now we can add the first line to the CSV file. This contains the headings of the data:

fputs($fp, "id, name, email, result");

The ►C1 at the end of the string indicates a line break. If we did not add it, subsequent data would be pasted behind instead of on a new line. Please note that this only works in strings with double quotes.

We repeat the following loop as long as records can be fetched. This puts the data into the CSV file.


while($uitslag = $pds->fetch(PDO::FETCH_ASSOC)) {
	fputcsv ($fp, $uitslag, ','); 
}

When writing to the file, we are helped by the fputcsv() function. It writes the array to the CSV file. The third argument of this function is the separator. Instead of the comma (,), we could also use another separator, such as the semicolon (;). To finish off, we close the file:

fclose($fp);

The entire script:

 PDO::ERRMODE_EXCEPTION)
                  );
	$query = "SELECT id, naam, email, resultaat FROM Uitslagen";
	$pds = $db->query($query); 
} catch(PDOException $ex) {
   	echo "An Error occured: " . $ex->getMessage(); 
	exit();
}	

header('Content-Type: text/csv' );
header('Content-Disposition: attachment; filename="uitslagen.csv"');

$fp = fopen('php://output', 'w');	
fputs($fp, chr(0xEF) . chr(0xBB) . chr(0xBF) );
fputs($fp, "id, naam, email, resultaat\r\n");
while($uitslag = $pds->fetch(PDO::FETCH_ASSOC)) {
	fputcsv ($fp, $uitslag, ','); 
}
fclose($fp);
?>

SQL Basics training

Are you interested in learning this programming language? Discover with an SQL training course data that previously remained hidden for you. In our two-day SQL Basis training, you will learn all the important ins and outs of SQL!

link]

Save visitor passwords safely with PHP? Use Hashing!

You regularly read in the newspaper or on the Internet that passwords of Internet users are on the street, and that while website creators can easily prevent this. Find out how you can prevent password theft by reading this blog!

What is the danger?

Unlike computers, people are not very good at remembering. Yet you have to remember passwords for everything. As a result, many people use one password for several websites. This brings a big security risk. If a password is leaked, all accounts where this password is reused are immediately accessible.

How do you prevent theft of visitor passwords?

The best solution to prevent passwords from being stolen is simply not to store them! Instead, we are going to store the hash of the password. A hash function makes a password unrecognisable. Based on the hash, it is impossible to retrieve the input. A hash function always gives the same result for the same input. A strong hash function also ensures that two different texts do not result in the same hash (if this does happen there is a collision). Even if hackers succeed in obtaining a database with hashes, they still do not have any passwords.

How do you use PHP's hash functions?

Since PHP 5.5, it has become very easy to hash out passwords using the function password_hash(). This function has one mandatory argument: the password. In addition, the second argument can be used to specify which hashing algorithm should be used. If this is not specified, the strong BCrypt algorithm is used by default. In addition to hashing, this function also adds a Salt which protects against Rainbow Tables. The hash generation is as follows:

 
  $password = 'Secret Password
  $hash = password_hash($password, PASSWORD_BCRYPT);
  echo $hash;

The generated hash is a string of 60 characters and can look like this: $2y$10$Se3mLsHueAYTM3G4Wd9hTuyfzPCRYtafImcOSO2U0H4290jPU.SGO. From this hash, it is impossible to retrieve the password. So you can safely store this hash in your database.

To check if someone has entered a correct password we use the function password_verify(). We give it two arguments, the password entered at login and the hash we stored.


  $hash = '$2y$10$Se3mLsHueAYTM3G4Wd9hTuyfzPCRYtafImcOSO2U0H4290jPU.SGO';
  $wachtwoord = 'Onzin';

  if (password_verify( $wachtwoord, $hash)){
      echo 'Correct wachtwoord';
  } else {
    echo 'Incorrect wachtwoord';
  }

In this case, the user password will produce a different hash to the one stored in our database. This way we can check if the entered password is correct, without having to save the original password. Even if a hacker gains access to our database, there is no password to be found.

Trainings PHP

Did you know that Learnit offers various trainings in PHP? During our training PHP Programming Basics helps you a lot in the world of PHP with practical examples. In the training PHP Programming Continuation we bring your PHP programming skills to a higher level, giving you a professional programming style and teaching you all the techniques needed for a mature web application. Click here for the complete overview of Learnit's PHP training courses.