Switch to: V11V10V9V8V7V6V5

valentina_fetch_array()

Declaration

array valentina_fetch_array ( 
           resource result,
          [int result_type] )

Parameters

Name Description
resultThe result resource that is being evaluated. This result comes from a call to val_query().
result_type The type of array that is to be fetched. It's a constant and can take the following values: VALENTINA_ASSOC, VALENTINA_NUM, and the default value of VALENTINA_BOTH.

Description

Returns an array that corresponds to the fetched row and moves the internal data pointer ahead.

Return Values

Returns an array that corresponds to the fetched row, or FALSE if there are no more rows. The type of returned array depends on how result_type is defined. By using VALENTINA_BOTH (default), you'll get an array with both associative and number indices. Using VALENTINA_ASSOC, you only get associative indices (as valentina_fetch_assoc() works), using VALENTINA_NUM, you only get number indexes (as valentina_fetch_row() works).

Examples

Example 1.

<?php
valentina_connect("localhost", "val_user", "val_password") or
   die("Could not connect: " . valentina_error());
valentina_select_db("mydb");
 
$result = valentina_query("SELECT id, name FROM mytable");
 
while ($row = valentina_fetch_array($result, VALENTINA_NUM)) {
   printf("ID: %s  Name: %s", $row[0], $row[1]);  
}
valentina_free_result($result);
?> 

Example 2.

<?php
valentina_connect("localhost", "val_user", "val_password") or
   die("Could not connect: " . valentina_error());
valentina_select_db("mydb");
 
$result = valentina_query("SELECT id, name FROM mytable");
 
while ($row = valentina_fetch_array($result, VALENTINA_ASSOC)) {
   printf("ID: %s  Name: %s", $row["id"], $row["name"]);
}
 
valentina_free_result($result);
?> 

Example 3.

<?php
valentina_connect("localhost", "val_user", "val_password") or
   die("Could not connect: " . valentina_error());
valentina_select_db("mydb");
 
$result = valentina_query("SELECT id, name FROM mytable");
 
while ($row = valentina_fetch_array($result, VALENTINA_BOTH)) {
   printf ("ID: %s  Name: %s", $row[0], $row["name"]);
}
 
valentina_free_result($result);
?> 

Example 4.

<?php
valentina_connect("localhost", "val_user", "val_password") or
   die("Could not connect: " . valentina_error());
valentina_select_db("mydb");
 
$result = valentina_query("SELECT table1.id AS 'id1', table2.id AS 'id2' FROM mytable WHERE table1.name = table2.manager");
 
while ($row = valentina_fetch_array($result, VALENTINA_BOTH)) {
   printf ("ID: %s  Name: %s\n", $row[0], $row[1]);
   printf ("ID: %s  Name: %s\n", $row["id1"], $row["id2"]);
}
 
valentina_free_result($result);
?> 

Notes

Performance: An important thing to note is that using valentina_fetch_array() is not significantly slower than using valentina_fetch_row(), while it provides a significant added value.

Note: Field names returned by this function are case-sensitive.

Note: This function sets NULL fields to PHP NULL value.

Note: When specifying aliases for columns as in exapmle 4, remember to put them into single quotes -

 SELECT id as 'aliasID'..

See Also