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
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
Mobile Dev World

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 : 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 Update Picture
Gianugo Rabellino
Date : Jan 17th 1999
Grade : 2 of 5 (graded 4 times)
Viewed : 12134
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Gianugo Rabellino
Action : Grade This Code Example
Tools : My Examples List

  Submit your own code examples 
 

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. Currently supports Mysql, mSQL (untested), PostgreSQL and ODBC.

Beware: this is ALPHA code, use it at your own risk!



<?

/*
* SAL - SQL Abstraction Library
* version 0.01
* Gianugo Rabellino <nemorino@opera.it>
*
* - 28/07: MySQL Support - mSQL support
* - 29/07: PostgreSQL Support
* - 03/08: ODBC Support
*/

/*
*
* Set the variable $dbtype to any of the following
* values: MySQL, mSQL, Postgres, ODBC before including
* this library
*
*/

/* $dbtype = "MySQL"; */
/* $dbtype = "mSQL"; */
/* $dbtype = "PostgreSQL"; */
/* $dbtype = "ODBC"; */



/*
* SQL_connect($host, $user, $password, $db)
* returns the connection ID
*/

function SQL_connect($host, $user, $password, $db)
{
global $dbtype;
switch ($dbtype) {

case "MySQL":
$conn=mysql_pconnect($host, $user, $password);
mysql_select_db($db);
return $conn;
break;;

case "mSQL":
$conn=msql_pconnect($host);
msql_select_db($db);
return $conn;
break;;


case "PostgreSQL":
$conn=pg_pconnect($host,"5432","",$db);
return $conn;
break;;

case "ODBC":
$conn=odbc_pconnect($db,$user,$password);
return $conn;
break;;

default:
$conn=mysql_pconnect($host, $user, $password);
mysql_select_db($db);
return $conn;
break;;


}

}

/*
* SQL_query($host, $user, $password, $db)
* executes an SQL statement, returns a result identifier
*/

function SQL_query($query, $id)
{
global $dbtype;
switch ($dbtype) {

case "MySQL":
$res=mysql_query($query, $id);
return $res;
break;;

case "mSQL":
$res=msql_query($query, $id);
return $res;
break;;

case "PostgreSQL":
$res=pg_exec($id,$query);
return $res;
break;;

case "ODBC":
$rid=odbc_prepare($id,$query);
$res=odbc_execute($rid);
return $res;
break;;


default:
$res=mysql_query($query, $id);
return $res;
break;;

}
}

/*
* SQL_num_rows($host, $user, $password, $db)
* given a result identifier, returns the number of affected rows
*/

function SQL_num_rows($res)
{
global $dbtype;
switch ($dbtype) {

case "MySQL":
$rows=mysql_num_rows($res);
return $rows;
break;;

case "mSQL":
$rows=msql_num_rows($res);
return $rows;
break;;

case "PostgreSQL":
$rows=pg_numrows($res);
return $rows;
break;;

case "ODBC":
$rows=odbc_num_rows($res);
return $rows;
break;;

default:
$rows=mysql_num_rows($res);
return $rows;
break;;
}
}


/*
* SQL_fetchrow($res,$row)
* given a result identifier, returns an array with the resulting row
* Needs also a row number for compatibility with PostgreSQL
*/

function SQL_fetch_row($res, $nr)
{
global $dbtype;
switch ($dbtype) {

case "MySQL":
$row = array();
$row = mysql_fetch_row($res);
return $row;
break;;

case "mSQL":
$row = array();
$row = msql_fetch_row($res);
return $row;
break;;

case "PostgreSQL":
$row = array();
$row = pg_fetch_row($res,$nr);
return $row;
break;;

case "ODBC":
$row = array();
$cols = odbc_fetch_into($res, $nr, &$row);
return $row;
break;;

default:
$row = array();
$row = mysql_fetch_row($res);
return $row;
break;;
}



}

/*
* SQL_fetch_array($res,$row)
* given a result identifier, returns an associative array
* with the resulting row using field names as keys.
* Needs also a row number for compatibility with PostgreSQL.
*/

function SQL_fetch_array($res, $nr)
{
global $dbtype;
switch ($dbtype) {

case "MySQL":
$row = array();
$row = mysql_fetch_array($res);
return $row;
break;;

case "mSQL":
$row = array();
$row = msql_fetch_array($res);
return $row;
break;;

case "PostgreSQL":
$row = array();
$row = pg_fetch_array($res,$nr);
return $row;
break;;

/*
* ODBC doesn't have a native _fetch_array(), so we have to
* use a trick. Beware: this might cause HUGE loads!
*/

case "ODBC":
$row = array();
$result = array();
$result = odbc_fetch_row($res, $nr);
$nf = count($result)+2; /* Field numbering starts at 1 */
for($count=1; $count < $nf; $count++) {
$field_name = odbc_field_name($res, $count);
$field_value = odbc_result($res, $field_name);
$row[$field_name] = $field_value;
}
return $row;
break;;

}
}
?>



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
PostGreSQL and MySQL 2 in 1 db Manager
Categories : PHP, PHP Classes, Databases, PostgreSQL, MySQL
bookmarker - PHP, PHPLIB, MySQL WWW based bookmark manager
Categories : MySQL, PHP, MySQL, Complete Programs, Databases
Multiple Search using PHP and Mysql
Categories : PHP, Databases, General SQL, MySQL
How to Insert a Date Format Into MySQL from PHP
Categories : PHP, Databases, MySQL, Date Time, Beginner Guides
Paginating the mySQL data
Categories : PHP, Algorithms, Databases, MySQL, HTML and PHP
AITSH Download
Categories : PHP, Complete Programs, MySQL, Databases
Save and restore files into postgresql database (PHP SCRIPT) PHP CLASS
Categories : PHP, Databases, PostgreSQL, Filesystem
http://phpMySearch.web4.hm - The phpMySearch search engine system is a completeworld wide web indexing and searching system for a small domain or intranet.
Categories : Search Engines, PHP, Databases, MySQL
A very simple and efficient split bar the B-Z bar , for mysql and php ... Tired of obfuscated code try this one ...
Categories : PHP, Databases, MySQL, Algorithms
This functions makes it easy to use session-variables known from ASP. With one Cookie the array "session" will save and restore from a db-record. In this version MySQL is used but it's should very easy to change
Categories : PHP, Arrays, Cookies, MySQL, Databases
DDN FFA Network Script
Categories : PHP, MySQL, Complete Programs, HTML and PHP, Databases
mysql date/time converters
Categories : PHP, MySQL, Databases, Date Time
SQL / PHP based Integrated Authentication
Categories : PHP, Authentication, Databases, MySQL
Newbie Notes #10 - Generating drop downs
Categories : PHP, MySQL, HTML, Beginner Guides, Databases