Well, learning and being told to change your processes are always annoying! We seem to have to say it a
lot on this site. Mostly it is because those learning was steered to a site that knows less than they should.
This site is full of great programmers that are really here only to help and learn better ways to do their own
work. So, do not hesitate to ask anything you need.
I updated several of my old test sites to the improved version of MySQL and found it was so easy, that I think
you will not have problems with it. As in the code you posted, you just have to change the way you connect
to the database. This creates a pointer to the connection. Quite often it is just $conn. So, your one line of
MySQL : $result=mysql_query($sql); Would be : $result=mysqli_query($conn, $sql); Easy change.
You can change your code one page at a time. There is no need to change it all at once. If you have a
large number of pages, you probably have one connection string page. You can add in a second one that
uses the MySQLi version. Just name the connection variable a different name than the current one. Then,
upgrade one page at a time using the new version. Should be easy. The general layout for a MySQLi
connection is loosely like this:
// Variables for connecting to your database. These variable values come from your hosting account.
$hostname = “localhost”; // This depends on your server
$dbname = “zzz”;
$username = “zzz”;
$password = “zzz?”;
// Connecting to your database
$db_connect = mysqli_connect($hostname, $username, $password, $dbname);
// Check if connection was actually made
if (mysqli_connect_errno()) { echo "Failed to connect to the database system! Error: " . mysqli_connect_error(); }
You can skip the variables and just put the values into the connect() function if you want. Very similar to
your old connection to the database. The $db_connect was used to not be confused with the standard
$conn that you might be using…
Here is a nice tutorial on this that might help. Lots of info if you walk thru the “Next-Chapter” links…
http://www.w3schools.com/php/php_mysql_connect.asp
This also shows the PDO examples which are also quite easy and is more versatile for you to learn in the
future as this is the way PHP is heading. (OR, actually already there…)
Hope this helps!