Why can't you use deprecated mysql_* functions in PHP and what to use instead?
Hello everyone! I'm a beginner PHP developer learning from old textbooks. In all examples, connecting to a MySQL database looks like this:\n\n```php\n$link = mysql_connect('localhost', 'root', '');\nmysql_select_db('my_database', $link);\n$result = mysql_query("SELECT * FROM users WHERE id = " . $_GET['id']);\nwhile ($row = mysql_fetch_assoc($result)) {\n echo $row['name'];\n}\n```\n\nEverything works, but I see that in modern PHP these functions cause errors. The logs say they are deprecated. On forums, people say they were completely removed in PHP 7. I understand that I need to switch to something new, but I don't understand: what exactly is the problem with mysql_*? They work, after all. What makes them dangerous? And what should I use instead — mysqli or PDO? What's the difference? I would be grateful for a detailed explanation with examples, so that
No answers yet.
Log in to leave an answer