The script is not a "tutorial" but a tester that will run on most versions
of MySQL and from about versions 4.5 of PHP all the way up to the current version.
What makes you sure? The OP stated the script is a part of a tutorial. Moreover, if you head over to tizag and look at their
mysql connect tutorial, you see a script remarkably similar to what the OP posted (the lack of a call to
mysql_connect in the posted script likely being a mistake on the OP's part, one that is causing the error). The script in the tutorial isn't to test connecting to MySQL; it illustrates how to create a connection and is then built upon to show how to perform other tasks.
[...]I do not know where 'misson' received the authority to command us to "ignore" anything
much more "ignore" the world we study and work in.
Experience gives me the
ability to offer
advice. You're free to disagree, but that doesn't justify copping an attitude. The snarky tone is just uncivil.
The OP is attempting to learn how to access MySQL from PHP. Any tutorial that is based on the old mysql driver is out of date, almost certainly doesn't teach best practices and probably does teach bad habits (such as using "
or die(mysql_error())" for error handling without qualification). The use of the old mysql driver is basically a tutorial smell. Once he's learned the modern way of interfacing with MySQL in PHP, OP can learn outdated interfaces, if he wants.
By the way, are those air quotes around my handle?
Introduction to PHP - PDO
From above link
[...]PDO ships with PHP 5.1, and is available as a PECL extension for PHP 5.0; PDO requires the new OO features in the core of PHP 5, and so will not run with earlier versions of PHP.
PHP 4 is past the end of its lifetime. Installing PHP 5 is a trivial task for an admin; any host that doesn't offer PHP5 is either lazy or doesn't know what they're doing. PHP 4 can be left installed for legacy code, but new code should be based on PHP 5. This is the position of the PHP developers, who stopped supporting PHP 4 in 2008.
When you are testing for why your PHP/MySQL code is not working
better to test without PDO and be sure it is your code and not
how PHP/MySQL, on your system, is implemented
OP is learning, not testing.
PDO isn't an implementation detail. If PDO is an option, there's no reason to use the old mysql driver;
new PDO("mysql:host=$host", $user, $pw) will work or fail as
mysql_connect($host, $user, $pw);. If PDO isn't an option, mysqli is a better choice than mysql. A better choice still is to find a modern host.