Version: 2.0.x
Type: Function
Category: Databases
License: GNU General Public License
Description: A function to perform database queries on MySQL servers. Takes one argument; The SQL statement.
<?PHP /* Function to simplify doing Database Queries All that is needed is the query to execute. Returns true if execution was completed successfully. Otherwise outputs error messages and returns 0. Requires 4 global variables: $db_host The hostname / IP-Adresse $db_user The username $db_pass The password $db_name The database name Version: 2.0.1 Date: 2000-07-01 Author: Jocke Selin ([email protected]) ---------------------------------------------- For direct output in the same function Version: 2.0.x Date: 2001-03-20 Update: rolandz ([email protected]) */ function jquery($query) { $db_host='10.130.148.15'; $db_user='root'; $db_pass=''; $db_name='Focus'; // Connect to DB if (!$link = @mysql_connect($db_host, $db_user, $db_pass)) { $result = 0; print("<FONT COLOR='Red'><BR><BR><HR><CENTER><B>Error connecting to $db_host!<HR></B><BR>n"); } else { // Select DB if (!@mysql_select_db($db_name, $link)) { $result = 0; print("<FONT COLOR='Red'><BR><BR><HR><CENTER><B>Error selecting $db_name!<HR></B><BR>n"); } else { // Execute query if (!$result = @mysql_query($query, $link)) { $result = 0; print("<FONT COLOR='Red'><BR><BR><HR><CENTER><B>Error executing query!<HR></B><BR>n"); } else { $fields = mysql_num_fields($result); while ($array = mysql_fetch_array($result)) { for ($i=0; $i <= $fields; $i++) { echo $array[$i]; if ( $i < $fields ) echo "; "; } echo "<BR>n"; } } } } return $result; } function bgn_html($title, $author, $header) { print ("<HTML>n"); print (" <HEAD>n"); printf (" <TITLE>%s</TITLE>n", $title); print (" <META HTTP-EQUIV='Content-Type' CONTENT='text/html; charset=windows-1252'>n"); printf (" <META NAME='AUTHOR' CONTENT='%s'>n", $author); print (" </HEAD>n"); print (" <BODY BGCOLOR='#F1F1F1' TEXT='#364180'>n"); print (" <BASEFONT FACE='Courier New'>n"); printf (" <H1><CENTER>%s</CENTER></H1>n", $header); printf (" <HR>n"); } function end_html () { print (" </BODY>n"); print ("</HTML>n"); } bgn_html ('Test PHP-Site', 'rolandz', 'Output'); jquery('SELECT * FROM table WHERE field = x'); end_html (); ?>