准备(),执行()不工作

时间:2017-01-22 10:39:04

标签: php sql pdo execute prepare

当我在准备好后尝试执行Statement时,没有更新任何内容。

PHP代码:

if ($action == 'update' ) {
echo "<h2 class='text-center'>Update Member</h2>";
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $userid      = $_POST['userid'];
    $username    = $_POST['username'];
    $pass    = $_POST['password'];
    $md5pass = md5($pass);

准备开始在这里

    //Update REcords
    $stmt = $con->prepare("UPDATE users SET UserName = ? WHERE UserID = ? ");
    $stmt->execute(array($username, $userid));

    if ($stmt->rowCount() > 0) {
        echo "User Data has been updated.";
     }  

PDO sql连接:

<?php
$dsn  = 'mysql:host=localhost;dbname=kdz';
$user = 'root';
$pass = '';
$option = array(
    PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8',
);

try {

    $con = new PDO($dsn, $user, $pass, $option);
    $con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

}

catch(PDOException $e){
    echo 'Faild To Connect'. $e->getMessage();
}

&GT;

专业人士能解决吗?

0 个答案:

没有答案