<script language="php">
#
# this include file has the passwords and
# database names defined in it
#
require('../sql_passwords.php');
echo "<h1>SQL select & update statements</h1>\n";
#
# connect to SQL
#
$link = mysql_connect($z_hardcoded_sqlurl,
$z_hardcoded_database,
$z_hardcoded_password )
or die('Could not connect: ' . mysql_error());
#
# select the database I want to use
#
mysql_select_db($z_hardcoded_database) or die('Could not select database');
echo "<table border=0>\n";
echo "<tr><td>\n";
#
# select some stuff from the database
#
$query = 'SELECT name, count FROM `counters` ';
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
$query=preg_replace ( '/from/i', '<br> from', $query);
#
# i am not sure but i think this frees the
# stuff associated with the current select so
# you can do a new select
#
// Free resultset
mysql_free_result($result);
echo "</td><td>\n";
$query = 'SELECT count FROM `counters` where name=\'test\'';
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
$query=preg_replace ( '/from/i', '<br> from', $query);
$query=preg_replace ( '/where /i', '<br> where ', $query);
$query=preg_replace ( '/order /i', '<br> order ', $query);
#
# display the selected stuff
#
echo "<table border=2>\n";
echo "<tr><td colspan=2>$query</td></tr>";
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo "<tr>\n";
foreach ($line as $col_value) {
if ($col_value == '' ) {
$col_value=' ';
}
echo "<td>$col_value</td>\n";
$nextval=$col_value;
}
echo "</tr>\n";
}
echo "</table>\n";
#
# i am not sure but i think this frees the
# stuff associated with the current select so
# you can do a new select
#
// Free resultset
mysql_free_result($result);
echo "</td></tr>\n";
#
# add 1 to the counter
#
# update the counter value
#
$nextval=$nextval+1;
$query = 'update `counters` set count='.$nextval.' WHERE name=\'test\'';
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
#
# display the table with the updated value
#
echo "<tr><td>\n";
echo "</td><td>\n";
$query=preg_replace ( '/from/i', '<br> from', $query);
$query=preg_replace ( '/where /i', '<br> where ', $query);
$query=preg_replace ( '/order /i', '<br> order ', $query);
#
# display the selected stuff
#
echo "<table border=2>\n";
echo "<tr><td colspan=2>$query</td></tr>";
echo "</table>\n";
echo "</td></tr>\n";
echo "<tr><td>\n";
#
# select some stuff from the database
#
$query = 'SELECT name, count FROM `counters` ';
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
$query=preg_replace ( '/from/i', '<br> from', $query);
#
# i am not sure but i think this frees the
# stuff associated with the current select so
# you can do a new select
#
// Free resultset
mysql_free_result($result);
echo "</td><td>\n";
$query = 'SELECT count FROM `counters` where name=\'test\'';
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
$query=preg_replace ( '/from/i', '<br> from', $query);
$query=preg_replace ( '/where /i', '<br> where ', $query);
$query=preg_replace ( '/order /i', '<br> order ', $query);
#
# display the selected stuff
#
echo "<table border=2>\n";
echo "<tr><td colspan=2>$query</td></tr>";
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo "<tr>\n";
foreach ($line as $col_value) {
if ($col_value == '' ) {
$col_value=' ';
}
echo "<td>$col_value</td>\n";
}
echo "</tr>\n";
}
echo "</table>\n";
#
# i am not sure but i think this frees the
# stuff associated with the current select so
# you can do a new select
#
// Free resultset
mysql_free_result($result);
echo "</td></tr>\n";
echo "</table>\n";
#
# close the SQL connection
#
// Closing connection
mysql_close($link);
</script>