��� ����� ��� pg_num_rows
(PHP 4 >= 4.2.0, PHP 5)
pg_num_rows — Returns the number of rows
Description int pg_num_rows ( resource result )
pg_num_rows() will return the number of rows in a PostgreSQL result resource. result is a query result resource returned by pg_query() . This function will return -1 on error.
Замечание: This function used to be called pg_numrows() .
Yet even simpler example:
$query = «SELECT * FROM atable»;
$result = pg_query($query);
if (pg_num_rows($result)>0) <
while($row=pg_fetch_object($result) <
echo $row->first_column;
echo $row->second_column;
.
echo $row->last_column;
>
>
else <
echo «The query did not return any data!»;
>
$sql = «select * from YOURTABLE»;
$result = pg_query($sql);
$rows = pg_num_rows($result);
for ($i = 0; $i COLUMNNAME»;
>
simple pg_num_fields & pg_num_rows example.
$result = pg_query($conn, $string);
while($arr = pg_fetch_array ($result)) <
for ($x=0;$x
$result = pg_query($conn_id, $query);
echo pg_num_rows($result);
postgresql � �������� ���������� php-������� (�������� ����������) ��� �������� ����������� ������ ��� �������� csv �� ������
� ������� ������� ���������� �� PHP � Postgres.
� �������, ��� �������������� SQL ������� � CSV, �� � ������, ��� �������������� � CSV, ����� ��� ������ SQL �������� ����������.
� ��� ������� ������ �� ���� �������� �������� html-������, �������, ��� ��� �������, � ��������� � �������� �������� GET.
� ����� ��������, �� ���, ��� � ���� �����, ��� ��� �������������� ������� SQL-������, ���������� ���� �������.
������ � �� ��������� � ������� ���� ������ �����-�� ����������� ������������ ����, ��� � �������� �� ���������� $find � ����� $field �� ����� ������������� ������� ������ � ���� ����� sql ��� ����� �������� php csv, ��������� ������� php ����� �� ������ ��������.
������ pg_num_rows
� ���� ������ � ���� ����
� ��������� PHP5 MYSQL ��� ��� ������������ ���, � �� ����, ������ ��� �� �����:
4 ������
��� ����� ������������ mysql_num_rows($result) — pg_num_rows($result) ������ ��� PostreSQL, ������ � ��������.
pg_num_rows ��� postgres, ����� ��������� ���, �� ������ �������� �� mysql_num_rows
����, ����� ���������� �� ������ �������
- ��� ������ �� �������� / �� ���������� � ������� postgres
- �� ��������� ������ ���������� �����������, ���� �������, ��� �� ��������� �������� SQL
pg_num_rows ����� ������� PostgreSQL, ���������� ������������ mysql_num_rows ������.
pg_num_rows ��� �������, ������� ����� ������ PostgreSQL � ������� ���������� �����, ��������� � ���. ��� ����� ��������� �������� PostgreSQL ��� PHP, ������� ���������� �� ���������� ��� ����������� ������� ��������� WAMP. ������ �� ���, �� ����� ����, ������ �� ������������ � ���������� Postgre.
������ ���� �������� � ���, ��� �� ��������� ������ MySQL ������� Postgre. ��� �� ���������. �������� mysql_num_rows ,
php — ��������������: pg_num_rows() ������� ����� 1 ��������, 0 �������� � PHP
� ���� ���� ���������� ��������� ������
��������������: pg_num_rows() ������� ����� 1 ��������, 0 �������� � /var/www/funcoes.php � ������ 52
��� ��� �������:
-
2 2
- 7 ��� 2020 2020-06-07 02:53:41
- user2623414
2 ������
��������������: pg_num_rows() ������� ����� 1 ��������, 0 �������� � /var/www/funcoes.php � ������ 52
������ ������� ���� �� ����
- 7 ��� 2020 2020-06-07 02:53:42
- meda
pg_num_rows ��������� ���������� ���������� � �������� ���������. ������ ������� ���, ��� �������� ���������, �� ����� �� ��� ������������.
��. ������� �������: int pg_num_rows ( resource $result )
������ ���������� ������� PostgreSQL, ������������ pg_query(), pg_query_params() ��� pg_execute() (����� ������)
����� �������, ��� ��� ������ �������� ��������� ������� �� pg_num_rows , ��� ������ ����:
(�������� ��������, ��� pg_num_rows ���������� ����, ���� �� ���������� � ������������� � ������� �������� DO INSTEAD , ������� � ����������/��������� ��������� � �.�.)
��������������: pg_num_rows() �������, ��� ������ 1 ��������, 0 ��������� � PHP
��������� ������ ���������� � ���� ����
��������������: pg_num_rows() �������, ��� ������ 1 ��������, 0 ��������� � /var/www/funcoes.php �� ����� 52
��� ��� �������:
������ 15 ���. 13 2013-12-15 15:30:00 user2623414
����� ����� ������ � ���� ������ ��������� ������? � JJJ 15 ���. 13 2013-12-15 15:31:57
�� — ������ ������������� ����������. �� � ��� ������ ��������� ��������? � Lix 15 ���. 13 2013-12-15 15:33:09
2 ������
��������: pg_num_rows() �������, ��� ����� 1 ��������, 0 ��������� � /var/www/funcoes.php �� ����� 52
������ ������� ���� �� ����
������ 15 ���. 13 2013-12-15 15:33:20 meda
pg_num_rows ��������� ��������� ������ ���������� � �������� ���������. ������ ������� ���, ��� �������� ���������, �� ����� �� ��� ������������.
�������� ��������� �������: int pg_num_rows (resource $result)
PostgreSQL ��������� ������� �������, ������������ pg_query(), pg_query_params() ��� pg_execute() (����� ������)
����� �������, ��� ��� ������ �������� ��������� ������� pg_num_rows , ��� �������� ����:
(�������� ��������, ��� pg_num_rows ������ ����, ���� �������� � ������������� � DO INSTEAD ���������, ������� �������� ��������/������� � �.�.)
������ 15 ���. 13 2013-12-15 15:34:01 Rogiel Sulzbach
��� ������ ����������? ��� ������, ��� �� �������� � ������� ����. ��, ��� �� ����� �������, ��������� ����-�� ����������/��������� ��� � ���� ������� ���� — ��� �� ���������� ���� . � Lix 15 ���. 13 2013-12-15 15:35:09
������� ������ — ��� ������, ��� � �������� . � Rogiel Sulzbach 15 ���. 13 2013-12-15 15:36:55
�� — �� ** ����������� ** �������� ����������� � ���, ��� �������� �����������. �� �� ��������� �� ���� � ����� ������. ���� OP ������� ���������� ���� ������ ��� ��������� ����, ������, �� ������ ������, ��� ������� ������� � ����� ������������? � Lix 15 ���. 13 2013-12-15 15:37:50
@Lix ��� ����� �������� ������, ������ �� ��� �� ��������������� ���, ���� �� ����������, ��� ��� ���-�� �� �������? � user1789769 15 ���. 13 2013-12-15 15:54:49
@jenny — ��� ���� ����� — ���������� ������ ������ ����������. � ��� ����� ����� ������� � ������������� ��� ���������, �������, ��� � �����, �� ������ ����, �� ��� �� ������� OP ����� ������ ������������ ������ ������. � Lix 15 ���. 13 2013-12-15 16:01:09
��, � ���� � ���������, ����������� � ���, ��� �� ��� ����������� ����� ��� �� ������� ��������. ���� OP ��������� ��� ������ ��� ��������� ������ ����, ������ ��� ����� �������� ��� ��� ������ ������ �� [so]. ������ ����� ���� �����, � �� ���������������. � Lix 15 ���. 13 2013-12-15 16:02:08
����� ����� ����� ��������, ��� �������� ����� �� ����� ������� �� ���. ����� ������������ ��������� � ����������� � ���������. ����������� ������������ ���� ��������� � ���� — �� ��� ��� � ������, ��� ����� ���������� ���� ������� �������: P � Lix 15 ���. 13 2013-12-15 16:03:37
������ pg_num_rows
0 Hulk [2011-08-15 16:38:00]
� ���� ������ � ���� ����
� ��������� PHP5 MYSQL ��� ��� ������������ ���, � �� ����, ������ �� �� �������:
function php mysql
4 ������
��� ����� ������������ mysql_num_rows($result) — pg_num_rows($result) ������ ��� PostreSQL, ������ � ��������.
3 ajreal [2011-08-15 16:41:00]
pg_num_rows ��� postgres, ����� ��������� ���, �� ������ �������� �� mysql_num_rows
imho, ����� �� �������� ������ �������
- ��� ������ �� ��������/���������� � ������� postgres
- ���������� �� ����� ��������� �����������, ���� �������, ��� �� ��������� ������������ SQL-���
pg_num_rows — ��� �������, ������� ����� ������ PostgreSQL � ������� ���������� ��������� � ��� �����. ��� ���� ��������� �������� PostgreSQL ��� PHP, ������� �� ���������� � ������� ����� ������� ��������� WAMP. �� ����� ���� ������ �� ��� �� ������������ � ���������� Postgre.
������ �������� ����������� � ���, ��� �� ��������� ������ MySQL � ������� Postgre. ��� �� ���������. ���������� mysql_num_rows .
0 Deele [2011-08-15 16:43:00]
pg_num_rows — ������� PostgreSQL, ������ ����� ���������� ������������ mysql_num_rows .
pg_num_rows
(PHP 4 >= 4.2.0, PHP 5, PHP 7)
pg_num_rows � ���������� ���������� ����� � �������
��������
pg_num_rows() ���������� ���������� ����� � ���������� ������� PostgreSQL.
����� ������� ���������� pg_numrows() .
������ ����������
��������� ������� PostgreSQL, ������������ ��������� pg_query() , pg_query_params() ��� pg_execute() (� �������).
������������ ��������
���������� ����� � �������. � ������ ������ ���������� -1.
�������
������ #1 ������ ������������� pg_num_rows()
= pg_query ( $conn , «SELECT 1» );
$rows = pg_num_rows ( $result );
echo «���������� �����: » . $rows . «.\n» ;
?>
��������� ���������� ������� �������:
�������� �����
- pg_num_fields() — ���������� ���������� ����� � �������
- pg_affected_rows() — ���������� ���������� ���������� �������� ������� (��������)
User Contributed Notes 3 notes
As mentioned, if you are performing an INSERT/UPDATE or DELETE query and want to know the # of rows affected, you should use pg_affected_rows() instead of pg_num_rows().
However, you can also exploit postgres’s RETURNING clause in your query to auto-select columns from the affected rows. This has the advantage of being able to tell not only how many rows a query affects, but exactly which rows those were, especially if you return a primary-key column.
// Example query. Let’s say that this updates five rows in the source table.
$res = pg_query ( «Update foo set bar = ‘new data’ where foo.bar = ‘old data’ » );
pg_num_rows ( $res ); // 0
pg_affected_rows ( $res ); // 5
pg_fetch_all ( $res ); // FALSE
// Same query, with a RETURNING clause.
$res = pg_query ( «Update foo set bar = ‘new data’ where foo.bar = ‘old data’ RETURNING foo.pkey» );
pg_num_rows ( $res ); // 5
pg_affected_rows ( $res ); // 5
pg_fetch_all ( $res ); // Multidimensional array corresponding to our affected rows & returned columns
?>
Not sure why this documentation doesn’t have the following note:
Note: Use pg_affected_rows() to get number of rows affected by INSERT, UPDATE and DELETE query.
Found on other resources. Adding here in case someone else is looking for the info.
��� ��������� �� �� ����� ����� SQL-��������. ������� ������� PostgreSQL
� � ���������� ���������, ��� ������ ������������, ���� ����� ������������ postgresql, �� �������� ������� �������, ������ �� �����-�� ������ ������ ��� ���������. �� ��� � ������ ������ ����������� �� StackOverflow ��������� ���� �row_number() OVER ()�, �� �������� � ������. � ���� ������� ������� � ����������� ���������� PostgreSQL.
�������� ��-�������� ���������, ��� ����� �� ������������.
��� ������ ���� ����� ��������, ��� ������� ������� �� �������� �������, � ������ ��������� ��������� �������������� ���������� � ���. �.�. ��� �������� ��������� ����� �������, ��� postgres ������� ��������� ���� ������ (����� ���������� � limit), � ����� ������ ������������ ������� ���������.
��������� �������� �����:
���� � ��� ��������� ���������, ����������� ����� �����, ������� ����� ������������ ������� � ������� ���� ���������.
������ ���� ����� ���� ������ ������ ������� �������� (), �.�. ����� �������� ��� ������ ���������� �������.
��������, � ���� ������� � ������� ����� id, header � score ������ ��������� ��������� �����.
� ������� ��������� ����� �������� ORDER BY, ����� ����� �������� ������� ���������.
�������� ��������, ��� � ������� ��� � � ����� ����� ������ ORDER BY id, ��� ���� ������� �������� ��� ����� �����. �.�. ������� ������ ������������ ��������� ������ � ����������� ������ ������� �������, ���� order ������ �� ������ �������.
������ � ������. � ������� ��������� ����� �������� ����� PARTITION BY [expression],
�������� row_number() OVER (PARTITION BY section), ����� ������� ����� ���� � ������ ������ ��������:
���� �� ��������� ��������, �� ��������� �������� ���� ������.
��� ����� ���� ������� ������� � ��������, ������� ����� ������������, ��� ��� ���� ����� ������ �����.
� �������� ������� ����� ������������, ��� �������, �������� ������� ������� �� ������� � ��� row_number(), rank(), lead() � �.�., � ����� ������������ �������-��������, ����� ���: sum(), count() � �.�. ��� ���, ��� �����, ���������� ������� �������� ������ ��-�������: ���� �� ����� ORDER BY � ����, ���� ������� �� ���� �������� ���� ���, � ��������� ������� �� ��� ������ (�������� ��� ���� ����� ��������). ���� �� ORDER BY �����, �� ������� � ������ ������ ���� �� ������ �������� �� ���� ������.
������� ��������� ��� �� �������. ��������, � ��� ���� ����� (����������� � �������) ������� ���������� ��������.
� �� ����� ������ ������, ��� ������� ������� �� ������� ��� ����:
�.�. ��� ������ ������ ���� ������� � ��������� ������. � ������ ������ ����� � ��� ����� ����� �� ������ �� ������� ������ (���� ���� �� PARTITION BY, �� �� ������ ��������).
���� �� �� ��� ���������� ������ sum �� ����� ������������ ORDER BY � ����, ����� �� ������ ��������� ����� ����� � ������� � �� ���� �������. �.�. ������� ��� ������ �� ����� ����� ���� ����� �����
�� ������ �� ����� ��������.
��� ����� ����������� ���������� �������, ���� �� ������������ ��� �������. �� ��� ������, ��� ��������-���� ��������, ���������� ����������� ������ SQL-���������.
������� ������� ����� ������������ ����� �� ��������� ����, ��� ���� ����� ������ �� ������, ����� �� ��� � ��� �� ��������.
���� � ��� ����� ���������� ��������� ����� OVER, �� ����� ���� �� ��� � ������� �������� � �������� ������ WINDOW, ����� �������� ������������ ����. ��� ������ �� �������:
����� w ����� ����� OVER ���� ��� ��� ������.
��������� ������ ������� ������� ���������� ������������� � ������� � ������� WHERE, ������ ��� ������� ������ ����������� ����� ���� ���������� � �����������, �.�. � ���, ��� ����������. ������� ����� �������, ��������, ��� 5 �������� � ������ ������, ���� ������������ ���������:
��� ������ ��� �����������. ������ row_number() ���� ��������� ������ �������. �������� lag, ������� ���� ������ ����� ��������� ������� ������. � ������� �� ����� ����� ��������� ����� ������� ������� �� ���������� � ��������:
����� � ����������� �������� ��������, ��� �������� ������ ��������� ������� ������. � �����, ����� � ���� ����� ���������� ��������, ���� ������� �������.
�������������� �� ������� � ���������� «�������� ����», ��� �� ��������� ���� ������, ����� ���������������� � �� �� �����!
pg_num_rows
pg_num_rows — ���������� ���������� �����.
��������
int pg_num_rows (resource result)
pg_num_rows() ���������� ���������� ����� � PostgreSQL result -�������.
result ��� ����� ���������� ���������� �������, ������������ �� pg_query() . ��� ������� ���������� -1 ��� ������.
����������: ����������� pg_affected_rows() ��� ��������� ���������� �����, ��������������� � ������� INSERT, UPDATE � DELETE.
����������: ��� ������� ���������� pg_numrows() .
pg_num_rows
(PHP 4 >= 4.2.0, PHP 5)
pg_num_rows � Возвращает количество строк в выборке
Описание
pg_num_rows() возвращает количество строк в результате запроса PostgreSQL.
� анее функция называлась pg_numrows() .
Список параметров
� езультат запроса PostgreSQL, возвращаемый функциями pg_query() , pg_query_params() или pg_execute() (и прочими).
Возвращаемые значения
Количество строк в выборке. В случае ошибки возвращает -1.
Примеры
Пример #1 Пример использования pg_num_rows()
= pg_query ( $conn , «SELECT 1» );
$rows = pg_num_rows ( $result );
echo «Возвращено строк: » . $rows . «.\n» ;
?>
� езультат выполнения данного примера:
Смотрите также
- pg_num_fields() — Возвращает количество полей в выборке
- pg_affected_rows() — Возвращает количество затронутых запросом записей (кортежей)