WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Index
PHP Web Logs (BLogs)
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
Submit Site
Forex Trading Online forex trading platform

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : Initializing the MSQL-tables via a 2-dimens array
Categories : mSQL, PHP, Databases Update Picture
Arthur de
Date : Jun 07th 1998
Grade : 3 of 5 (graded 4 times)
Viewed : 6410
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Arthur de
Action : Grade This Code Example
Tools : My Examples List

  Submit your own code examples 
 

A good way of organizing/controling the initializingstage is to use a 2-
dimensional array filled with your
SQL-statementstrings. Each category has its own array. Now you can loop through
the categories ,
execute the statements and see whether they succeeded or not. It can be done
this way:

<?

$Dbname = Firstbase;
$First_table = Person;
$Sec_table = Action;
$Third_table= Users;
$Autoid_table = Autoid;

$actions = array (
/************** DROP TABLES ********************/
// Delete all the tables. This also
// deletes all the indices and sequences.
array(
"DROP TABLE $First_table",
"DROP TABLE $Sec_table",
"DROP TABLE $Third_table",
"DROP TABLE $Autoid_table"
),

/***************** CREATE TABLES ********************/
array (
"create table $First_table(UID int,F_name char(17),L_name char(20)".
", Birth date,Phone char(10), Email char(25))",
"create table $Sec_table(Idnr int,Dow char(10),Date_out date".
",Time_out time,Datetime_in char(28))",
"create table $Third_table(id char(25),pw char(25))",
"create table $Autoid_table(Id_num int)"
),

/************ CREATE INDICES & SEQUENCE ***************/
array(
"CREATE UNIQUE INDEX index1 ON $First_table(UID)",
"CREATE INDEX index2 ON $First_table(F_name)",
"CREATE INDEX index3 ON $First_table(L_name)",
"CREATE UNIQUE INDEX index4 ON $Sec_table(Idnr)",
"CREATE INDEX index5 ON $Sec_table(Date_out)",
"CREATE INDEX index6 ON $Third_table(id,pw)",
"create sequence on $Autoid_table step 1 value 0"
)

); // end of 2-dimensional array

/*************** EXECUTE QUERIES **********/

for ($counter = 0; $counter <= 2;$counter++) {
$number = count($actions[$counter]); // count number of array-elements
for ($teller = 0; $teller < $number ;$teller++) {
echo $actions[$counter][$teller];
$result = msql($Dbname, $actions[$counter][$teller]);
if ($result > 0){
ECHO " = Succesfull.<br>";
} else {
ECHO " = Unsuccesfull.<br>";
}
}
}

?>

The "droppings" will cause warningmessages the first time you execute them
because there were no
tables to drop since you haven't created them yet.



Logs hits to any page which includes it. Automatically utilises page access information left behind by PHP/FI2.0.
Categories : Databases, PHP, mSQL, Databases
Returns the last row from a select where multiple rows have been selected. In this case it is used to determine the last number in an AUTO_INCREMENT column. I use it to create "ticket numbers" or anything that needs a unique ID in sequence.
Categories : mSQL, MySQL, Databases, PHP
user-authentication with php3 and msql
Categories : Authentication, mSQL, PHP, Databases
This program allows you to upload an ODBC ressource - i.e. an MS-Access database to a MySQL server.
Categories : Databases, MySQL, Complete Programs, PHP, Databases
An SQL Administration User Interface for the Web
Categories : Databases, PHP, mSQL, Complete Programs
msql -- Send mSQL query
Categories : PHP, PHP Functions, mSQL, mSQL
databases administration remote Web
Categories : mSQL, PHP, Complete Programs, Databases
This is Yet Another Sql Abstraction Library. Include it in your script and you can use the most important SQL functions without worrying about the SQL backend.
Categories : Databases, PHP, ODBC, MySQL, PostgreSQL
Cut your MySQL Connections to 1 line of code
Categories : PHP, Beginner Guides, Databases, MySQL
PhpIBadmin - Web interface to Interbase RBDMS , this is a port of phpMyadmin
Categories : Databases, InterBase, PHP
simple script to send emails via a html-form to different users
Categories : Email, MySQL, PHP, Databases
Displaying records of database in more than one page (paging)
Categories : Databases, MySQL, PHP
Function Query2Array will read an PEAR-DB-Query-Result into an Array. You may specify a Column used as Array-Keys, and you may specify the Number of Rows to skip at the beginning and the Number to fetch (-1 = infinite).
Categories : Functions, PHP, Databases
html split bar used to split in multiple pages a database result
Categories : HTML and PHP, Databases, MySQL, PHP
Tropicalm Genetree Family (MySQL based family tree)
Categories : PHP, Interfaces, Databases, MySQL, Complete Programs