$sql=<<<EOF
INSERT user (username,password,email) VALUES("傅1", "'.md5('fhfjy').'","fhfjy@126.com"),
("傅2", "'.md5('fhfjy').'","fhfjy@126.com"),
("傅3", "'.md5('fhfjy').'","fhfjy@126.com")
EOF;
================================
插入后,去数据库里看到的密码是: '.md5('fhfjy').' 这样的!
用变量替代只能
^-^...
<?php //PDO try{ // $pdo = new PDO('mysql:host=localhost;dbname=test', 'root', '123456', options) $pdo = new PDO('mysql:host=localhost;dbname=test', 'root', '123456'); $sql = <<< EOF CREATE TABLE IF NOT EXISTS users( id INT UNSIGNED AUTO_INCREMENT KEY, username VARCHAR(32) NOT NULL UNIQUE, password CHAR(255) NOT NULL, email VARCHAR(255) NOT NULL ); EOF; $res = $pdo->exec($sql); var_dump($res); echo "exec() ? ".$res.": 0 <br/>"; // define('pwd', 'pdw0001', case_insensitive); $pwd = "pwd&md5"; $pwd1 = "pwd@md51"; $pwd2 = "pwd$md52"; $salt = "salt_md5"; $md5 = crypt($pwd, $salt); echo "md5:{$md5}<br/>"; $md51 = crypt($pwd1, $salt); echo "md5:{$md51}<br/>"; $md52 = crypt($pwd2, $salt); echo "md5:{$md52}<br/>"; $str = md5("Shanghai"); echo ("Shanghai:".$str."<br/>"); $sql = <<< EOF INSERT users(username,password,email) VALUES ("u01","$md5","u01@ufo.xyz"), ("u02","{$md51}","u02@ufo.xyz"), ("u03","$md52","u03@ufo.xyz"); EOF; echo "{$sql}<br/>"; $res = $pdo->exec($sql); var_dump($res); echo "<br/>"; echo "exec() ? ".$res.": 0 <br/>"; }catch(PDOException $e){ echo ($e->getMessage()); } ?>
http://www.imooc.com/qadetail/131282?t=158630#id_158630
$sql = <<<EOF
INSERT user(username,passwd) VALUES("u01","'.md5()'"),("u02","'.md5('pwd').'"),("u03","'.md5()'");
EOF;
EOF;// EOF; 结束符要顶格写(前面不可以有空格!)
google:
http://stackoverflow.com/questions/20931450/parse-error-syntax-error-unexpected-t-sl
<?php
// PDO
try{
$pdo = new PDO("mysql:host=localhost;dbname=test", 'root', '');
$sql = <<< EOF
INSERT user(username,passwd) VALUES("u01","'.md5()'"),("u02","'.md5('pwd').'"),("u03","'.md5()'");
EOF;
$result = $pdo->exec($sql);
}catch(PDOException $e){
echo $e->getMessage();
}
//To print a list of all the drivers that PDO currently supports, use the following code:
$xxx = var_dump(PDO::getAvailableDrivers());
echo ($xxx);
?>
Parse error: syntax error, unexpected '<<' (T_SL) in G:\wwwRoot\php\pdo_md5.php on line 5