Questions about PDO and MySQL,

Source: Internet
Author: User
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; 
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.