PHP 8.4.0 RC3 available for testing

mysql_unbuffered_query

(PHP 4 >= 4.0.6, PHP 5)

mysql_unbuffered_queryMySQL に SQL クエリを送信するが、結果に対してのフェッチやバッファリングは行わない

警告

この拡張モジュールは PHP 5.5.0 で非推奨になり、PHP 7.0.0 で削除されました。 MySQLi あるいは PDO_MySQL を使うべきです。詳細な情報は MySQL: API の選択 を参照ください。 この関数の代替として、これらが使えます。

説明

mysql_unbuffered_query(string $query, resource $link_identifier = NULL): resource

mysql_unbuffered_query() は SQL クエリ query を MySQL に送信します。その際、 mysql_query() が行っているような自動バッファリングを 行いません。一方、この挙動により SQL クエリが消費するメモリの量を おさえられます。また、最初の 1 行目が取得されたらすぐに処理を はじめることができます。SQL の処理が完全に終わるまで待つ必要がありません。 複数の DB 接続を利用する場合には、オプションのパラメータ link_identifier を指定する必要があります。

パラメータ

query

実行する SQL クエリ。

クエリ内のデータは 適切にエスケープ する必要があります。

link_identifier

MySQL 接続。指定されない場合、mysql_connect() により直近にオープンされたリンクが指定されたと仮定されます。そのようなリンクがない場合、引数を指定せずに mysql_connect() がコールした時と同様にリンクを確立します。リンクが見付からない、または、確立できない場合、E_WARNING レベルのエラーが生成されます。

戻り値

SELECT, SHOW, DESCRIBE あるいは EXPLAIN では、 mysql_unbuffered_query() は 成功した場合に resource 、エラー時に false を返します。

UPDATE, DELETE, DROP, などその他の SQL 文では、 mysql_unbuffered_query() は 成功した場合に true 、エラー時に false を返します。

注意

注意:

mysql_unbuffered_query() の利点には、以下のような 代償があります: mysql_unbuffered_query() から返される結果セットには、 すべての行をフェッチするまでは mysql_num_rows()mysql_data_seek() を使用できません。また、結果の行をすべてフェッチするまで、 同じ link_identifier を使って MySQL に新しいクエリを送信することができません。

参考

add a note

User Contributed Notes 3 notes

up
3
frappyjohn at dos2linux dot org
21 years ago
Don't let the two hands confuse you, these are both advantages (they should really be on the same hand):

On the one hand, this saves a considerable amount of memory with SQL queries that produce large result sets.

On the other hand, you can start working on the result set immediately ...
up
3
crazyone at crazycoders dot net
16 years ago
You are NOT required to read all rows from the resultset when using unbuffered query, you may opt out at any time and use mysql_free_result. Imagine looking at 1 million row when the first 50 suffice? Just free the result and you are good to go again.
up
0
post at jfl dot dk
20 years ago
If using optimized MyISAM tables I guess there is a big advantage with this function as it is possible to do selects and inserts on the same time as long as no rows in the table gets updated.
To Top