MySQL and PHP connection using PDO

PHP & MySQL tutorial using PDO

Although there are millions of tutorials about MySQL and PHP, I decided to make mine but in a very very simple way. Before you start, you must have a basic knowledge in MySQL.

MySQL and PHP connection using PDO

Source code of PHP file connection

It is worth mentioning that we will not see good practices of databases, relationships, etc. We will use the tables as they are, without looking at normalization, or things like that.

Note: this tutorial uses PDO, but remember that we can also use mysqli functions. Personally I recommend PDO, because it is object oriented. However, I hope to write a tutorial about mysqli in the future.

Continue reading…

How does the plugin for thermal printers work

A plugin for printing in thermal printers directly from browser

In this post I will introduce to you a plugin for printing tickets, receipts or invoices on a thermal printer using client-side JavaScript even if your web page or application is on a cloud server.

This plugin allows you to print directly from browsers, without dialogs and without browsers compatibility issues because you only have to send a HTTP request to print silently and in the background.

Continue reading…

Ticket sample

Print receipt in thermal printer using JavaScript, CSS & HTML

In this post I will show you how to print a ticket or receipt by using JavaScript (client side) and a thermal printer. At the end we will have a great ticket that looks like this:

Ticket sample

Receipt printed in thermal printer using JavaScript only

Obviously you can change the font family, size, logo and so on. And remember: we will be using only pure CSS, HTML & JavaScript, no frameworks; though you can use any framework to render the content before printing.

You can see the demo here, and the full code on my GitHub.

Continue reading…

Diálogo con layout personalizado en Android

Custom alert dialog in Android

Dialog and AlertDialog with custom layout on Android

In this post I will show you how to create custom dialog on Android using a layout created by us, that is, create a custom alert by adding elements such as EditText, Button, etc.

Custom alerts on Android serve to display an alert that is not a confirmation alert, since we can define a custom layout.

To achieve this we will use the Dialog and AlertDialog.Builder classes.

Continue reading…

How to redirect in Spring Boot

Redirect in the Spring Boot framework

In this post I will show you how to redirect or direct the user to another URL within the method of a controller in the Spring Boot framework.

Redirecting to another URL in Spring Boot is very useful when the user does a certain action and we must return it to the main page.

Continue reading…

Change express-generator app port

The express-generator package helps a lot in the development of web applications with Node, because it generates the skeleton of an application.

A small disadvantage is that, when generating the code, we do not know how to change some very basic things, for example, the port on which the app listens (the default port is 3000).

In this post I will show you how to change the port in some app generated by express-generator. Continue reading…

Generar sal para OpenCart

Reset OpenCart user password manually (in database)

Today we will see how to reset the OpenCart password (e-commerce system in PHP) manually, directly in the database; generating the hash and the salt manually with a function created by me.

Function that generates salt and new password

Here I leave the code, and the explanation at the end.

The function returns an array that has the salt and the password, the way to call it is to pass the password in plain text. You can try and use the function here.

Once you have the salt and the password just do an update of your database table.

In my case:

My table is called oc_user because when I installed OpenCart I used that prefix, in your case it can vary.

The algorithm and the way that OpenCart uses it

Thanks to OpenCart is open source we can see how it generates the salt and saves the hashes.

In its source code it implements obtaining a cryptographically secure random string and then uses sha1 to hash it, concatenating it with the user’s password.

The generation of the salt is as follows:

Generar sal para OpenCart

Generate salt for opencart password

It uses the function called token defined in helpers/general. php and then calls it, obtaining a random string of 9 digits. Then concatenate it and hash it with SHA1:

Hashear contraseña de OpenCart con SHA1

Hashed OpenCart password with SHA1

Finally, in the database it saves everything in the user table in the salt and password fields:

Ubicación de sal y contraseña de usuario en base de datos OpenCart

Salt location and user password in OpenCart database

Knowing all those things we could write a function that generates the salt and the password to be able to reset the password of a user manually in OpenCart.

How to install Node.js and NPM on Android using Termux app

In this post we will see how to install Node.Js and NPM (Node package manager) in Android.

At the end we will be able to run Node.js applications as if we had a Linux server.

We will also see how to install dependencies using the npm install command, since it is a possible thing in Android thanks to Termux.

Specifically we will install version 6.9.0 of NPM and version 12.3.1 of node, although perhaps when you read this post you will install a newer version.

Continue reading…

5 - Insertar datos y probar base de datos

How to install MySQL (MariaDB) on Android with Termux

Install MySQL on Android

Android mobile devices are not designed to be servers (although some of them are powerful), however it is always interesting to see how technology advances and day by day we can do more things with our phones.

Today we will see how to install the MySQL or MariaDB server on Android, thanks to the Termux application. For that it is enough to execute a few simple commands and voila, we will have a MySQL database server in our Android; fully functional and ready to execute queries.

If we want to put it for production, we can do it as long as we configure security. In short, we will not see more advanced topics; we will only see how to install mysql on Android.

Here we will use MariaDB and MySQL as synonyms; that is, if you see that I say MariaDB do not get confused, I mean MySQL; and vice versa.

I know that there are really more differences especially with the licenses, but that is another topic and you can search it in Google if you wish.

Continue reading…

Cambiar nombre de sesión de Termux

Configure Termux on Android (Linux in our pocket)

Install Termux on Android

Today we will see how to install and configure Termux on Android, as well as a brief introduction to its use.

Termux is an application that will allow us to have a terminal on our device, but apart from that it gives us the possibility of installing very interesting packages; and if we configure them well and install well, we can have a complete and stable server on our mobile.

This application does not require root access, you only need that our Android phone has a recent version (I think it works from Android 6).

Continue reading…