Skip to main content

Posts

Showing posts with the label break statement in php

PHP Functions for Retrieving Metadata

The most complete way to retrieve metadata is by using a SELECT statement against the INFORMATION_SCHEMA database in the MySQL server. However, there are times that is overkill for the data needing to be collected for a PHP application. With that said, PHP offers multiple functions that provide methods for retrieving a small amount of metadata about the data in the MySQL server. Database Metadata The mysql_list_dbs() function retrieves the name of all the databases found on the server that are accessible by the user requesting the information: <?php // Load variables used in mysql_connect and connect to server include "connect_info.php"; $linkID1 = mysql_connect($dbhost,$dbuser,$dbpass) or die("Could not connect to MySQL server"); // Retrieve the names of the databases accessible by the user $schema_results = mysql_list_dbs($linkID1); print "The databases available to the root user are:<br>\n"; while (list($schema) = mysql_fetch

PHP Break and Continue

              With iterative control statements, PHP provides two means of manually interrupting the flow of the loops. These two commands include break (which has already been used in examples up to this point) and  continue.  The following example demonstrates how these two loop interrupts can be used in iterative control statements: <?php     for ($test=1; $test < 10; $test = $test + 1) {         if ($test==3) continue;         if ($test==6) break;         echo "The test number is $test<br>";     } ?> The following output would be displayed when this PHP script was run: The test number is 1 The test number is 2 The test number is 4 The test number is 5               When the  $test variable was equal to 3, the script skipped the remain code and performed the next  iteration of the for function.  This resulted in the number 3 not being printed. In addition, when the $test  variable was equal to 6, the break function ended the for function