I’m writing a PHP script that performs simple actions to a data base. In order to obtain the MySQL queries I use phpmyadmin to generates the PHP. When I generates using phpmyadmin the commands for example creates a table, this is the result:
$sql = "CREATE TABLE `pyr`.`table1` (`id` INT NOT NULL) ENGINE = MyISAM COMMENT = \'Some comments...\';";
If I insert this on my PHP script, it doesn’t work. However, if i remove the \, it works. What does the \ do?
It escapes the character
'so it can be written in your string. But you only have to escape the simple quote if your string is enclosed within single quotes. In your example, it’s enclosed within double quotes, so you don’t have to escape simple quotes! For example :