Android Question PDO PHP Select

fernando.oliboni

Active Member
Licensed User
Longtime User
Help please
See the SQL -> Select * from persons where id = 3456 ok?

I want to provide the table name like this ->
$table_name = $_GET["table"];
Select * from $table_name where id = 3456

how can I do this?
I've tried it all the way using sprintf and concatenations and stuff and I haven't been successful
 

aeric

Expert
Licensed User
Longtime User
You can use prepare statement and pass the value to a parameter.

I've tried it all the way using sprintf and concatenations and stuff and I haven't been successful
Can you show how your write your code?
 
Last edited:
Upvote 0

fernando.oliboni

Active Member
Licensed User
Longtime User
B4X:
   $nome = $_GET["nome"];
   $nome =  "%" . $nome . "%";
   $banco_cliente = $_GET["banco_cliente"];

    $select = sprintf( "select * from %s ", $banco_cliente , " where nome like :nome");

    $select = $pdo->prepare($select);
    
    $select-> bindValue(":nome", $nome);
    $select-> execute();
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
try
PHP:
$select=“SELECT * FROM “.$banco_clientele.” WHERE nome LIKE :nome”;
$db = $pdo->prepare($select);
$db-> bindValue(":nome", “%”.$nome.”%”);
$db-> execute();
 
Upvote 0

Douglas Farias

Expert
Licensed User
Longtime User
just a note, be careful with sql injection.
SQL:
select * from INFORMATION_SCHEMA.TABLES; DROP TABLE xxxxx;
you must treat the $_GET["banco_cliente"]; before using it directly in the query.

?
 
Last edited:
Upvote 0
Top