Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/242.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP将mysql_连接转换为PDO_Php_Mysql_Pdo - Fatal编程技术网

PHP将mysql_连接转换为PDO

PHP将mysql_连接转换为PDO,php,mysql,pdo,Php,Mysql,Pdo,我正在尝试将使用mysql_connect的代码转换为pdo,但是我不知道接下来该怎么做。应将结果落实到位 $query = "select * from tbl_usuarios where login = '$cliente_username' and senha = '$cliente_password'"; $result = $conexao->query($query); $number = $result->fetch(); if ($number==0) { ?&g

我正在尝试将使用mysql_connect的代码转换为pdo,但是我不知道接下来该怎么做。应将结果落实到位

$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);  

} 
?>
变成

$number->id
$number->nome

变成

$number->id
$number->nome
也许您应该在查询中添加限制1:

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

已解决$_会话['usuario_id']=$number['id'];$_SESSION['usuario_nome']=$number['nome'];