Galera preciso de ajuda para converter isso:
<code>
function PesquisaTabela($tabela){
//"de para" com nomes das tabelas
switch($tabela) {
case produto:
$newtable = 'srs_product';
break;
case categoria:
$newtable = 'srs_category';
break;
case entrada:
$newtable = 'srs_input';
break;
case saida:
$newtable = 'srs_output';
break;
case retirante:
$newtable = 'srs_requester';
break;
case fornecedor:
$newtable = 'srs_supplier';
break;
}
if($tabela != 'produto'){
return mysql_query("Select * from $newtable");
}else{
return mysql_query("Select a.id, b.nome as Categoria, a.nome, a.estoque_minimo, a.estoque_atual from srs_product a left join srs_category b on b.id = a.categoria or b.nome = a.categoria order by b.nome, a.nome");
}
}
</code>
Para PDO, iniciei algo, mais estou aprendendo e estou com dificuldades.
<code>
include 'connect.php';
function PesquisaTabela($tabela){
//"de para" com nomes das tabelas
switch($tabela) {
case produto:
$newtable = 'srs_product';
break;
case categoria:
$newtable = 'srs_category';
break;
case entrada:
$newtable = 'srs_input';
break;
case saida:
$newtable = 'srs_output';
break;
case retirante:
$newtable = 'srs_requester';
break;
case fornecedor:
$newtable = 'srs_supplier';
break;
}
if($tabela != 'produto'){
$consulta = $conexao->query("SELECT * FROM $newtable");
while ($linha = $consulta->fetch(PDO::FETCH_ASSOC))
}else{
$consulta = "SELECT A.ID, B.NOME AS CATEGORIA, A.NOME, A.ESTOQUE_MINIMO, A.ESTOQUE_ATUAL FROM SRS_PRODUCT A LEFT JOIN SRS_CATEGORY B ON B.ID = A.CATEGORIA OR B.NOME = A.CATEGORIA ORDER BY B.NOME, A.NOME";
$stm = $conexao->prepare($consulta);
$stm->bindValue(':a.id', $a.id);
$stm->bindValue(':b.nome', $b.nome);
$stm->bindValue(':a.nome', $a.nome);
$stm->bindValue(':a.estoque_minimo', $a.estoque_minimo);
$stm->bindValue(':a.estoque_atual', $a.estoque_atual);
$stm->execute();
$linha = $stm->fetch(PDO::FETCH_OBJ);
}
}
</code>