|
|
|
| Title : |
A database abstraction layer for the PHP 3.0 ODBC module. It supports persistent connections, fetching rows into arrays, prepare/execute (variable binding) and has a new and improved error interface. |
| Categories : |
Databases, PHP, Complete Programs |
 Stig Bakken |
| Date : |
Jan 17th 1999 |
| Grade : |
2 of 5 (graded 3 times) |
| Viewed : |
15174 |
| File : |
No file for this code example. |
| Images : |
No Images for this code example. |
|
| Search : |
More code by Stig Bakken |
|
| Action : |
Grade This Code Example
|
|
| Tools : |
My Examples List |
|
|
|
|
|
|
<?php // -*- C++ -*-
/*
* $Id: db-odbc.phl,v 1.7 1998/10/01 18:41:56 ssb Exp $
*/
$db_error_code = 0;
$db_error_msg = false;
$db_error_source = false;
/**
* @function db_connect
* @purpose Connect to a database
* @desc
* Connects to a database and returns and identifier for the connection.
* @arg database
* Data source name or database host to connect to.
* @arg user
* Name of user to connect as.
* @arg password
* The user's password.
*/
function db_connect($dsn, $user, $password)
{
$ret = @odbc_connect($dsn, $user, $password);
if (!$ret) {
db_check_errors($php_errormsg);
return false;
}
return $ret;
}
/*
* Function: db_query
* Arguments: $conn (int) - connection identifier
* $query (string) - SQL statement to execute
* Description: executes an SQL statement
* Returns: (int) 0 - query failed
* 1 - query succeeded
*/
function db_query($conn, $query)
{
$ret = @odbc_exec($conn, $query);
if (!$ret) {
db_check_errors($php_errormsg);
return false;
}
return $ret;
}
/*
* Function: db_fetch_row
* Arguments: $result (int) - result identifier
* Description: Returns an array containing data from a fetched row.
* Returns: false - error
* (array) - returned row
*/
function db_fetch_row($result)
{
$row = array();
$cols = @odbc_fetch_into($result, &$row);
if (!$cols) {
db_check_errors($php_errormsg);
return false;
}
return $row;
}
/*
* Function: db_free_result
* Arguments: $result (int) - result identifier
* Description: Frees all memory associated with a result identifier.
* Returns: (int) 0 - failure
* 1 - success
*/
function db_free_result($result)
{
$ret = @odbc_free_result($result);
db_check_errors($php_errormsg);
return $ret;
}
/*
* Function: db_disconnect
* Arguments: $connection (int) - connection identifier
* Description: closes a database connection
* Returns: (int) 0 - failure
* 1 - success
*/
function db_disconnect($connection)
{
$ret = @odbc_close($connection);
db_check_errors($php_errormsg);
return $ret;
}
/*
* Function: db_autocommit
* Arguments: $connection (int) - connection identifier
* Description: turn autocommit on or off
* Returns: (int) 0 - failure
* 1 - success
*/
function db_autocommit($connection, $enabled)
{
$ret = @odbc_autocommit($connection, $enabled);
db_check_errors($php_errormsg);
return $ret;
}
function db_commit($connection)
{
$ret = @odbc_commit($connection);
db_check_errors($php_errormsg);
return $ret;
}
function db_rollback($connection)
{
$ret = @odbc_rollback($connection);
db_check_errors($php_errormsg);
return $ret;
}
function db_quote_string($string)
{
$ret = ereg_replace( "'", "''", $string);
return $ret;
}
function db_prepare($connection, $query)
{
$ret = @odbc_prepare($connection, $query);
db_check_errors($php_errormsg);
return $ret;
}
function db_execute($statement, $data)
{
$ret = @odbc_execute($statement, $data);
db_check_errors($php_errormsg);
return $ret;
}
function db_error_code()
{
global $db_error_code;
return $db_error_code;
}
function db_error_msg()
{
global $db_error_msg;
return $db_error_msg;
}
function db_error_source()
{
global $db_error_source;
return $db_error_source;
}
function db_check_errors($errormsg)
{
global $db_error_code, $db_error_msg, $db_error_source;
if (ereg( 'SQL error: (\[.*\]\[.*\]\[.*\])(.*), SQL state (.....)',
$errormsg, &$data)) {
list($foo, $db_error_source, $db_error_msg, $db_error_code) = $data;
} else {
$db_error_msg = $db_error_source = false;
$db_error_code = 0;
}
}
function db_post_error($code, $message)
{
global $db_error_code, $db_error_msg, $db_error_source;
$db_error_code = $code;
$db_error_msg = $message;
$db_error_source = "[PHP][ODBC][db-odbc]";
}
function db_api_version()
{
return 10; // 1.0
}
?>
|
|
| 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 | | | Point and Click Interface ala MS Access for creating SQL statements. Categories : MySQL, Complete Programs, General SQL, PHP, Databases | | | Tropicalm Genetree Family (MySQL based family tree) Categories : PHP, Interfaces, Databases, MySQL, Complete Programs | | | 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 | | | phpAds, a complete banner and ad management system with detailled tracking and stats. Categories : MySQL, Complete Programs, Ecommerce, PHP, Databases | | | Shopping Basket On-Line Ordering System. Categories : Complete Programs, MySQL, PHP, Ecommerce, Databases | | | Example voting script. Lets people enter suggestions and vote for existing ones. Categories : MySQL, PHP, Cookies, Complete Programs, Databases | | | A set of functions sitting on top of the abstraction layer that makes it a little easier to do SQL stuff. Documentation is within Categories : Databases, ODBC, Complete Programs, PHP | | | Simple Mini Poll class library (SimPoll) Categories : PHP, PHP Classes, Databases, MySQL, Complete Programs | | | Browse a MySQL database & draw a tree view & load final items into a template page. Categories : MySQL, Complete Programs, Algorithms, PHP, Databases | | | free, search engine, indexing, system, information, web,
ftp, http, free, software, cgi, php, MySQL, database, php3,
FreeBSD, Linux, Unix, UdmSearch Categories : MySQL, Complete Programs, PHP, Databases, Search | | | Logs hits to any page which includes it. Automatically utilises page access information left behind by PHP/FI2.0. Categories : Databases, PHP, mSQL, Databases | | | Shopping Cart e-Commerce Solution Categories : Complete Programs, PHP, MySQL, Databases | | | DBE - Database Expander: Edit PostgreSQL individual database tables online via your Web browser! Categories : PostgreSQL, Complete Programs, Databases, PHP Classes, PHP | | | AITSH Statistics Categories : Complete Programs, Databases, HTML and PHP, Sessions, PHP | |
|
|
|