How to use the mysqli prepare function?

-4

It happens that googling a bit to know how to improve the security of a web system and protect a little against sql injections I read that one of the best ways is to use PDO however I am more familiar with mysqli so I intend to use the function prepare (If I'm not correct correct me). However, I still can not understand 100% how it works.

What I am most struggling with is the following: I am implementing a type of MVC and POO, as I had been handling the queries, it is generally like this: 1.- I have a file called conexion.php which contains both the connection and the methods that generate the queries.

2.- To generate the queries I have different files for example registrations.php where I instantiate the connection class to make queries, something like this :.

However, I still do not know what or how to modify to use the mysqli prepare function. I was just investigating about 2 hours and between what I could find I soaked a bit in the syntax (say 20%), however I can not understand how to apply it but keeping the same structure that I handle. I tried to do the following: But I throw the following error Then it is evident that it did not work.

Since I want to thank any kind of help, guidance, scolding, suggestion, bibliography and good luck messages. A huge greeting.

    
asked by Carlos Uriel 27.10.2016 в 23:22
source

1 answer

0

NOTE : How do you hit screenshots of the code? Please, edit your question and include the code in TEXT.

I have seen several errors in your code:

  • In point number 2 of your question, you can see in the second line (SQL query) that the fields idRegistroTipo and statusVal are strings .
  • At point number 3, however, you define two numeric fields id_uno e id_dos which you end up comparing with idRegistroTipo and statusVal and even if the engine allows you certain licenses, It's not right.
  • Your real problem is that you have a return $stmt just after the construction of the SQL, hence your code ends up failing, waiting to receive a mysqli_result .
  • answered by 27.10.2016 в 23:52