Home >Backend Development >PHP Tutorial >怎么理解此方法中的单双引号

怎么理解此方法中的单双引号

WBOY
WBOYOriginal
2016-06-13 10:14:00794browse

如何理解此方法中的单双引号

PHP code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--><?phpdefined ('ACC')||exit('Access denied');class userModel {    protected $table = 'user';    protected $db = false;    public function __construct() {        $this->db = mysql::getIns();    }    // 用户注册的方法    public function reg($arr) {        $sql = "insert into ". $this->table . "(username,passwd,email) values ('" . $arr['username'] . "','" . $arr['passwd'] . "','" . $arr['email'] . "')";             return $this->db->query($sql);       //print_r(mysql_error());    }}

那个sql语句里单双引号无论怎么看都不理解,忘朋友解疑!!!!!!!

------解决方案--------------------
如果这样写你是否能理解?
$sql = "insert into $this->table (username,passwd,email) values (' $arr[username]','$arr[passwd]','$arr[email]')";
------解决方案--------------------
你给的sql中 双引号是php的字符串定义符 ,单引号是sql字符串定义符
------解决方案--------------------
是的。就是拼接成sql串。
------解决方案--------------------
探讨
PHP code
defined('ACC')||exit('Access denied');

class userModel {
protected $table = 'user';
protected $db = false;

public function __construct() {
$this->db = mysql::getI……
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn