PHP将mysql_connection转换为PDO

时间:2014-10-11 21:29:12

标签: php mysql pdo

我正在尝试将使用mysql_connect的代码转换为pdo,但是我不知道在此之后该怎么做。应该放置" mysql_result"。

$query = "select * from tbl_usuarios where login = '$cliente_username' and senha = '$cliente_password'";
$result = $conexao->query($query);
$number = $result->fetch();

if ($number==0) { ?><script>alert('Dados incorretos! Tente novamente.');</script>
<?php
    exit;
} else {
    $_SESSION['usuario_id'] = mysql_result($result,0,'id');
    $_SESSION['usuario_nome'] = mysql_result($result,0,'nome');
    ?><script>document.location = '../principal.php'</script><?php
}
mysql_close($conexao);  

} 
?>

1 个答案:

答案 0 :(得分:0)

mysql_result($result,0,'id')

变为

$number->id

mysql_result($result,0,'nome')

变为

$number->nome

也许您应该向查询添加限制1:

$query = "select * from tbl_usuarios where login = '$cliente_username' and senha = '$cliente_password' limit 1";
相关问题