|
|
|
<?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 | | | bookmarker - PHP, PHPLIB, MySQL WWW based bookmark manager Categories : MySQL, PHP, MySQL, Complete Programs, Databases | | | 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 | | | Global Dump Highlighted Categories : PHP, Variables, Global Variables | | | 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 | | | getting the name of the current script and query string Categories : PHP, Global Variables, Variables, URLs | | | Retrieve text from table and email to your e-
address in pipe delimited format. Categories : PHP, MySQL | | | Accepts a database & hostname from a user and then HTTP username and password. Uses this to connect to a MySQL database. Produces a form based on the tables it finds there to allow the user to do SELECTs, INSERTs, and DELETEs. Categories : Databases, PHP, MySQL, Complete Programs | | | a function that builds an HTML select list from any mysql table. Categories : PHP, MySQL, HTML and PHP | | | phpAds, a complete banner and ad management system with detailled tracking and stats. Categories : MySQL, Complete Programs, Ecommerce, PHP, Databases | | | Point and Click Interface ala MS Access for creating SQL statements. Categories : MySQL, Complete Programs, General SQL, PHP, Databases | | | PHP4 MYSQL Authentication Script with cookie. Short & Sweet
Categories : Authentication, Apache, Cookies, PHP, MySQL | | | Message of the Day - Random Message (Needs MySQL!) Categories : Databases, HTML and PHP, PHP, MySQL | | | Check parameters validity. Paranoia was designed to check the validity of the parameters that a php page will receive after a form submission. It can be used to check the variables sent by POST or GET Categories : Algorithms, HTML and PHP, PHP, Variables | |
|
|
|