Formatting MYSQL call in PHP to TRIM
I am having difficulty running the following command in PHP开发者_开发知识库:
$con = mysql_connect("host", "username", "password") or die ("Unable to connect to server");
mysql_select_db("database") or die ("Unable to select database");
$sql = "UPDATE `table` SET `column` = TRIM(BOTH '"' FROM `column`)";
mysql_query($sql);
echo "quotation mark removed";
mysql_close($con);
The issue has to do with the syntax I believe. Specifically the BOTH '"' FROM
portion. How can I write this $sql call so that it will be understood by PHP?
This was my attempt BOTH '"."""."' FROM
You need to escape double quote (since you use it as a string delimiter), like:
$sql = "UPDATE `table` SET `column` = TRIM(BOTH '\"' FROM `column`)";
精彩评论