<?php
/* variable initialization
will initialize a global variable for every field in a given table
reduces coding later if a table structure changes
written by Victor M. Font Jr.
Abba Consulting group
http://abba.fontlife.com
*/
function initvar($varname, $value=null){
global $$varname;
if(!isset($$varname)){
if ($value == null){
$$varname = "";
}else{
$$varname = $value;
}
}
}
$sServer = "localhost";
$sUser = "your_user_id";
$sPass = "your_password";
$Database = "your_database";
$db = mysql_connect($sServer, $sUser, $sPass);
mysql_select_db($Database,$db);
// populate this array with the tables for which you are initializing variables
$sTableList = array("table1","table2","table3","table4","table5");
for ($n=0; $n<count($sTableList); $n++){
$id = @mysql_list_fields($Database, $table);
$count = @mysql_num_fields($id);
$results["num_fields"] = $count;
for ($i=0; $i<$count; $i++) {
$results[$i]["table"] = @mysql_field_table ($id, $i);
$results[$i]["name"] = @mysql_field_name ($id, $i);
$results[$i]["type"] = @mysql_field_type ($id, $i);
$results[$i]["len"] = @mysql_field_len ($id, $i);
$results[$i]["flags"] = @mysql_field_flags ($id, $i);
$results["meta"][$results[$i]["name"]] = $i;
}
@mysql_free_result($id);
for ($i=0; $i<$results["num_fields"]; $i++){
/*
if you want to initialize variables for types other
than strings and numbers, you'll have to add your own
type in the switch statment below
*/
switch ($results[$i]["type"]){
case "string":
initvar($results[$i]["name"]);
break;
case "int":
initvar($results[$i]["name"],0);
break;
case "blob":
initvar($results[$i]["name"]);
break;
}
}
}
?>
Initialize global variables for every field in a table.
This version requires that phplib is installed on your
server. Categories : Global Variables , MySQL , PHP , Variables How to make sure a that $foo is from a cookie and not from the URI. Categories : PHP , Variables , Global Variables , Cookies Make old style (PHP3) scripts using GET, POST, COOKIE and File uploads (POST) compatible with
PHP 4.2.0 Categories : PHP , HTML and PHP , Global Variables , Cookies , Variables bookmarker - PHP, PHPLIB, MySQL WWW based bookmark manager Categories : MySQL , PHP , MySQL , Complete Programs , Databases Global Dump Highlighted Categories : PHP , Variables , Global Variables getting the name of the current script and query string Categories : PHP , Global Variables , Variables , URLs Simple script to passing persistent and growing array between recalls of one page (manipulate little stack). Categories : Arrays , Global Variables , PHP , HTML and PHP , Variables FormWizard reads a mysql table and generates automatically
a html formular in a html-table Categories : PHP , MySQL , HTML Convert date's in YYYY-MM-DD (i.e. mysql format) into PHP3 timestamps. Also Find the difference in days between two PHP3 timestamps. Categories : HTML and PHP , PHP , MySQL , Date Time PhpLens PHP Application Server Categories : Content Management , Databases , PHP , MySQL Writing Portable MySQL Code in PHP: Porting to Oracle, Microsoft SQL
Server, Sybase, Interbase, PostgreSQL and other databases using ADODB
class library. Categories : MySQL , PHP , PHP Classes , ODBC , General SQL A login page that require username, password and userlevel. Categories : PHP , Security , Sessions , MySQL , Databases Database resultset navigation Categories : PHP , HTML and PHP , Databases , MySQL , Navigation This is a redirection program which is as good as the come.to v3 url
redirection, complete with admin interface all clients stored in mysql
Categories : PHP , MySQL , Ecommerce , HTML and PHP , Complete Programs This script is a contact form between users of a
website (kinda like the PM function on the forums)
Categories : PHP , Databases , MySQL , Regexps