Общие > Базы данных
Защита от недоразумений с выбором из таблички
Chs:
Англицким по бэкграунду же написано:
Placeholders and Bind Values
Some drivers support placeholders and bind values. Placeholders, also
called parameter markers, are used to indicate values in a database
statement that will be supplied later, before the prepared statement is
executed. For example, an application might use the following to
insert a row of data into the SALES table:
INSERT INTO sales (product_code, qty, price) VALUES (?, ?, ?)
or the following, to select the description for a product:
SELECT description FROM products WHERE product_code = ?
The "?" characters are the placeholders. The association of actual
values with placeholders is known as binding, and the values are
referred to as bind values.
When using placeholders with the SQL "LIKE" qualifier, you must remem-
ber that the placeholder substitutes for the whole string. So you
should use ""... LIKE ? ..."" and include any wildcard characters in
the value that you bind to the placeholder.
Соответственно никакие :DROP TABLE .... не пройдут.
DDHR:
Конечно Спасибо Вам, но я всё-таки и не понял как должен тогда выглядеть запрос к таблице? Я только на этой недели начал MySQL изучать...
?user=login
$user=param(\'user\');
$sth = $dbh->prepare("SELECT * FROM users where user = ?",$user)|| die "$DBI::errstr";
$sth->execute;
вот что по поводу LIKE:
... LIKE ...
Вернет TRUE (1) или FALSE (0)
???
Помогите запрос оформить правильно плз.
DDHR:
Всё, я понял!!!
Мне кажется, надо оформить так:
?user=login
$user=param(\'user\');
$sth = $dbh->prepare("SELECT * FROM users where user = ?")|| die "$DBI::errstr";
$sth->execute($user);
да/нет ?
commander:
-----------------------------------------------------------------------------------------
$user=param(\'user\');
$sth = $dbh->prepare("SELECT * FROM users where user = ?")|| die "$DBI::errstr";
$sth->execute($user);
-----------------------------------------------------------------------------------------
Навигация
Перейти к полной версии