If you want to stick with SQL standards then do neither. All you really need to do is to replace each single quote with two quotes.
$data = "O'Name"; // Not insertable
$data = str_replace("'","''",$data); // Insertable
This method works with all SQL databases including mysql.
However, mysql supports the non-standard method of using back slashes to escape certain characters. For some reason, php decided to use the slash method as default. Hence the majic_quotes nonsense.
Which method to use is up to you but if you ever plan on using standard sql databases in the future then you may as well do it right.