DEV Community

Julian
Julian

Posted on

How to Convert date format to PHP with MYSQLI, using secure queries to avoid SQL injection

There are cases in which we need to send a date format in Spanish to a sql query, for example the format of (Abril 28 2020) and for this we must do the following:

$ query = mysqli_query ($ conn, "SET lc_time_names = 'es_ES';");

$ query = $ conn-> prepare ('SELECT id, DATE_FORMAT (date, "% M% d% Y") ,, text FROM table WHERE id =?');

Keep in mind that these queries are what we should do in our developments to avoid sql injection.

Top comments (0)

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read more