Different versions of PHP

Hi,

I’m currently trying to learn PHP and MySQL and so far I have been happy with the results of what I have tried, but as always a lot of questions arrived.

I’m currently reading a book called PHP and MySQL from the Head First series and other one from this forum called PHP and MySQL (Kevin Yank) and I noticed that both books used different php functions to connect to a database, plus I also found a third method surfing the internet.

1 -mysql_connect()
2 -mysqli_connect()
3 -@mysql_connect()

So, now I’m wondering if this has something to do with different version of PHP, if this is the case this means that every time PHP is updated they change the syntax of the language?

Will code from previews versions work with newer versions of PHP? In other words if I code something today and later on I update the server to a newer version, will the server with the new version understand the code written with previews versions.

Can someone explain how PHP is usually updated and how this could affect my code.

Will I have to learn the new syntax and update my code with any new versions ?

Thanks

Will code from previews (sic) versions work with newer versions of PHP? In other words if I code something today and later on I update the server to a newer version, will the server with the new version understand the code written with previews versions.

Forward compatibility is pretty good. Functions do get deprecated (removed) from PHP, but it’s normally done over years. They will be marked as deprecated a long time before they are actually removed. PHP configuration such as register globals, magic quotes and enabled extensions have more to do with your code being able to run in different environments.

As SgtLegend said @ is an error suppressor. It’s not specific to mysql.
E.g


@file_get_contents('somefile.txt');
@unlink('another_file.txt');

It’s use is NOT usually recommended. Better to have your script handle the error in some way than just fail silently.

I recommend you use mysqli. If you can use it in an object oriented way do so, if not fine.

When they update the PHP core they don’t change the mysql core in a way that will affect you, they change it to improve the overall result of using it in the most simply terms.

One thing to note is that MySQL and MySQLi are the same basic coding style only MySQLi was introduced into MySQL 4.1.3 so only mysql works before that version. Also MySQLi and MySQL are different in a way as MySQLi allows for object oriented coding and procedural coding rather then just procedural coding.

PHP.net MySQL - http://php.net/manual/en/book.mysql.php
PHP.net MySQLi - http://php.net/manual/en/book.mysqli.php

And the last thing is that @ is NOT a different form of PHP MySQL coding, all @ will do is kill the script and give out no errors. So if @mysqli_connect was to fail you would get no visible errors but have errors in your PHP error log.

Thank a lot for your help, it starts to make sense.