PDO and MySQL problem, consult master?
The program is normal under window, but under Linux,
Register
Public Function Insert ($input) {
$time = time ();
$sql = "INSERT into". __db_prefix__. "Member (
' Email ',
' Password ',
' Secrecy_email ',
' Lock ',
' Add_time ',
' Last_login_time '
) VALUES (
'" . $input [' name ']. "',
'" . MD5 ($input [' Password ']). "',
'" . $input [' email ']. "',
0,
" . $time. ",
" . $time. "
)";
$stmt = $this->prepare ($sql);
if (! $stmt->execute ()) {
throw new Exception (Join (', $stmt->errorinfo ()));
}
}
This method works well, but:
Public function account ($name, $password) {
$sql = "Select member_id from Gm_member where email= ' mygirl ' and password= ' 25d55ad283aa400af464c76d713c07ad '";
$sql = "Select member_id from". __db_prefix__. "Member WHERE email= '". $name. "' and password= '". $password. "'";
$sth = $this->prepare ($sql);
$sth->execute ();
$stmt = $this->prepare ($sql);
if (! $stmt->execute ()) {
throw new Exception (Join (', $stmt->errorinfo ()));
}
Return ($stmt->rowcount () = = 1)? True:false;
}
}
This law cannot be used, why?
That is, insert is possible, but with SELECT, you can not find out, in MySQL with $sql this sentence test is a result of
Please master analysis, what is the cause??
------Solution--------------------
Do you have any error?
------Solution--------------------
PHP Code
Public function account ($name, $password) {$sql = "Select member_id from Gm_member where email= ' mygirl ' and password= ' 25d55 Ad283aa400af464c76d713c07ad ' ";//$sql =" Select member_id from ". __db_prefix__. "Member WHERE email= '". $name. "' and password= '". $password. "'";//$sth = $this->prepare ($sql);//$sth->execute (); $stmt = $this->prepare ($sql); if (! $stmt->execute ()) {throw new Exception (Join (', $stmt->errorinfo ())); }[color= #FF0000] $result = $stmt->fetch (PDO_FETCH_ASSOC);p rint_r ($result); [/color] Look at the results No! Return ($stmt->rowcount () = = 1)? True:false; }}
------Solution--------------------
PHP Code
Public function account ($name, $password) {$sql = "Select member_id from Gm_member where email= ' mygirl ' and password= ' 25d55 Ad283aa400af464c76d713c07ad ' ";//$sql =" Select member_id from ". __db_prefix__. "Member WHERE email= '". $name. "' and password= '". $password. "'";//$sth = $this->prepare ($sql);//$sth->execute (); $stmt = $this->prepare ($sql); if (! $stmt->execute ()) {throw new Exception (Join (', $stmt->errorinfo ())); } $result = $stmt->fetch (PDO_FETCH_ASSOC);p rint_r ($result); return ($stmt->rowcount () = = 1)? True:false; }}
------Solution--------------------
SQL code
$sql = "Select member_id from". __db_prefix__. "Member WHERE email=". $name. "and Password '". $password. "";
------Solution--------------------
SQL code
$sql = "SEL ECT member_id from ". __db_prefix__. "Member WHERE email=". $name. "and password=". $password;