Can a recordset be opened in PHP using one call?
Why is it necessary using 2 function开发者_运维问答s in PHP for opening a recordset? like:
$rc = mysql_query($sq, $db);
$rs = mysql_fetch_array($rc);
Can a recordset be handled also directly without mysql_fetch_array? What is the disadvantage?
mysql_query
returns a resource and not data.
You must fetch each row by some way mysql_fetch_array
can help you to move between the results (between pointers)
The way an SQL query is made, at least at the level of the C library that's used by PHP as an interface between PHP and the MySQL database, goes in two steps :
- Execute the query
- Fetch the results
The msql_*
functions are more or less based on that C-library (libmysql, before PHP 5.3 and its mysqlnd), and, so, work the same way.
Basically, the mysql_*
functions of PHP are nothing more than wrappers arround the functions exposed by libmysql
.
For more informations about the C library in question, see :
- MySQL C API
- C API Function Overview
No, because the first is used for database interrogation and the second is used for iteration of the array.
精彩评论