MySQL反引號的作用:? ? ` `
1.mysql中保留關鍵字不能用于表名和字段:
比如:create table key (報錯)
? ? ? ? create table `key` (正確)
? ? ? ? insert into test(abc) values(‘123’) (報錯)
? ? ? ? insert into test(`abc`) values(‘123’) (成功)
MySQL中加入PHP變量:
1.MySQL中加入PHP變量,第一種是用括號來區(qū)分變量
舉個栗子: $sql = "select * from table where name=‘{$name}’ and age={$age}";
2.或者用”.$v.”來連接:
舉個栗子:”insert into shop_good (good,words,author,state,name) values (‘“.$name.”’,5,10,15,20)”;
需要注意的是,這就涉及到PHP的基礎知識,”雙引號解析變量,單引號不解析變量”.
3.常用格式如1,2但是如果sql語句用"",為了書寫簡單,PHP變量可以不加單雙引號.
舉個栗子:$sql = "select * from table where name=$name and age=$age";
或者$sql = "select * from table where name='$name' and age='$age'";