Connecting to a MySql database, how modern?

I'm in php and thus mysql is not strong.

This question - as it is now is better and not "obsolete" to connect to the database? Know 3 ways: mysql_connect, mysqli and PDO.
Next video and article posted about 2 years ago. Everywhere says that that method is outdated, however no one uses it, etc.
As still correct, it is safer to connect to mysql in 2019?
I will be glad any new article, video, anything.

And another question about encrypting data, how to store them in a hidden form? You know you can use the library to do so, there is encryption, several mysql commands. But as a better and safer again?
March 23rd 20 at 19:46
8 answers
March 23rd 20 at 19:48
Good question, but incorrectly worded.
Because there are actually two questions - which driver to use and how to connect.
The answer to the first question is obvious. If you choose from mysql_connect, mysqli and PDO, then just go to the page of the manualdedicated to each option, and see what it says. Well or to try to use in your code and see what happens.

But the question is how to connect the remaining two options, really important, and the answer is, as usual, almost no one knows because all have each other write articles not 2, but 22-year-old. Fortunately, there are sites with relevant information.

Theoretically, you can use mysqli. But it is not necessary. Because it's a low level driver and use it without preparation is very inconvenient. But if that you're impatient, here's how to connect using mysqli

Key points:
- you want to set exceptions thrown
- you need to set the encoding
- when connecting you must catch the exception and throw it again, so no error message was username and password.

But the right answer, if you choose from these three will be PDO. Here is also not easy, so I look how to connect using PDO - given the same key points as stated above.

A good option is to use a higher-level abstraction of the type to do so. But since the normal documentation for it, but there is only a couple Haimovich video where it is used, and without any explanation or analysis of the fundamentals, then I would recommend redbean experienced developer, not a beginner. But in any case, as it to connect, it is written in the documentation

The password in the database is not encrypted and hashed. This is done poosu function password_hash
Thanks for the info! - susanna_Farre commented on March 23rd 20 at 19:51
And here I may seem strange, but for mysql, only mysqli recommend it stupidly due to the presence of asynchronous methods of interaction with DB. PDO doesn't do that. - otha0 commented on March 23rd 20 at 19:54
again a fan of PR your project - erich_Harv commented on March 23rd 20 at 19:57
March 23rd 20 at 19:50
if you plan to work with the database directly, PDO.
if you plan to use a higher level of abstraction/ORM, then the question to ask is not worth it (they already own all implements).
March 23rd 20 at 19:52
Separately, about passwords:
Oddly enough, on and off-site there is a good manual, which tells not only how, but why
Damn, I always forget about the first link.
Looking for a second, and there is, of course, for a beginner not chewed. - Jaiden_Quitzon10 commented on March 23rd 20 at 19:55
March 23rd 20 at 19:54
The PDO will be right.
what are you going to encrypt? the data in the database? traffic between the client and the server?
Yes, let's say on the website registration. I do not want to store passwords in the clear - susanna_Farre commented on March 23rd 20 at 19:57
@susanna_Farre, passwords, no one ever keeps in the clear. for this is the salt and hash - Kallie.Bechtelar commented on March 23rd 20 at 20:00
@Kallie.Bechtelar, but can you please tell us more about this? - susanna_Farre commented on March 23rd 20 at 20:03
@susanna_Farre, I probably could, but Google has it all chewed 100,500 times - Kallie.Bechtelar commented on March 23rd 20 at 20:06
@Kallie.Bechtelar, got it, thanks! - susanna_Farre commented on March 23rd 20 at 20:09
@susanna_Farre, please - Kallie.Bechtelar commented on March 23rd 20 at 20:12
March 23rd 20 at 19:56
Best for beginners about PDO is written here:
There's also a wonderful class to work with Mysql, substantially uprouse work:
Thanks, be sure to study - susanna_Farre commented on March 23rd 20 at 19:59
March 23rd 20 at 19:58
Friends, do you suggest forgetting about the fact that he's a rookie. How do you think he knows what the object is and whether to work with him? No longer does he have the desire to do anything after partial immersion in OOP? I think for a beginner the choice is obvious mysqli_connect. To say that one or the other way is safer, I would not, especially for a beginner, for safety you need to think about the connection method. Now work only with doctrine orm but started out the same way that sevens was removed. The PLO suffered not once, was enough "hurt", but procedure stamped with ease. All now pushed to the PLO, thereby killing the main advantage of php's low barrier of entry
Not to be confused with OOP syntax and object programming. Second, indeed, master no more than 10% of papernov. But the internal API is not OOP, it's stupid the same function as the side view. To draw an arrow with a function call - it's not as scary as you think. Write $mysqli->prepare($sql); is no more difficult than mysqli_prepare($mysqli, $sql);

While trying to ease the newbie life, you complicate it. Mysqli with prepared statements is the most unintuitive syntax in all PHP. That is because of fear to draw an arrow you condemn man to a real torment. - Jaiden_Quitzon10 commented on March 23rd 20 at 20:01
March 23rd 20 at 20:00
Briefly, mysqli is a modern method that uses pdo:) and therefore pdo is preferable since you can change the driver painless. Well, many things there are already automated.
In short, this answer is complete nonsense :) - Jaiden_Quitzon10 commented on March 23rd 20 at 20:03
double previous koment. - abel83 commented on March 23rd 20 at 20:06
@Jaiden_Quitzon10arguments? Pdo got its own connector? As far as I know only the wrapper pdo over mysqli, but when I put pdo in mysqli zavisimoti arrives. Is it not so? You can link to the source? - Aletha.Block commented on March 23rd 20 at 20:09
@abel83, a reference to to read what it is not, m? - Aletha.Block commented on March 23rd 20 at 20:12
As far as I know pdo is only a wrapper for the mysqli

The fact that this is a very ridiculous statement, from a series "heard a ring, Yes does not know where he is."
mysqli is also a wrapper. And PDO does not have any relation to it.
You're probably confusing mysqli with mysqlnd. - Jaiden_Quitzon10 commented on March 23rd 20 at 20:15
@Aletha.Block, let's Vice versa: a reference where to read that pdo is a wrapper around mysqli. - abel83 commented on March 23rd 20 at 20:18
Hmm, for a long time in pihu not a heap. :D
Never dug so deep in php since the 4-key, but it is not so difficult, so look both use mysqlnd:
#include <mysqld_error.h>
/* {{{ php_free_stmt_bind_buffer */
void php_free_stmt_bind_buffer(BIND_BUFFER bbuf, int type)

mysqlnd enabled by default, here's an example known to all remi-repo
 --with-pdo-mysql=shared,mysqlnd \

We will not go far, in the first article
there are quite nalgada picture 83ae02aded864136b2fce829ae2f6753.png

Well, Yes, that is clearly mysqli was used, yeah, there you got me, but in fact the driver one - mysqlnd. Is there another one that was deprecated in 5.x, I hope in 7-ke have dumped it all already guessed, we're talking about the mysql driver that is slow and works almost at the level of the shell

And in fact both libraries (with minor reservations) the same. They both just interface with libmysql (mysqlind), provides the programmer with a different approach to writing code, with its advantages and disadvantages.

Use PDO and don't use OOP is quite possible, especially for a beginner, but the growth vector in the direction of the PLO and the example of the PDO. - Aletha.Block commented on March 23rd 20 at 20:21
@Aletha.Block, so on a hot skillet looking for you will get an inferiority complex.

I don't understand if "for a long time in pihu not a heap", then why bother to go with the answers? Answer is about what you know. Is it really such a difficult rule? - Jaiden_Quitzon10 commented on March 23rd 20 at 20:24
March 23rd 20 at 20:02
I don't know about correct, but modern to use some the bike. For a beginner this is doubly true.

For small projects, for example, fit Medoo: easy, easy, normal documentation.

Find more questions by tags MySQLPHP