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 : 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 Update Picture
Stig Bakken
Date : Jan 17th 1999
Grade : 2 of 5 (graded 3 times)
Viewed : 16018
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

  Submit your own code examples 
 

<?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
Create and restore backup of MySQL databases
Categories : MySQL, Databases, PHP, PHP Classes, Complete Programs
Point and Click Interface ala MS Access for creating SQL statements.
Categories : MySQL, Complete Programs, General SQL, PHP, Databases
Example voting script. Lets people enter suggestions and vote for existing ones.
Categories : MySQL, PHP, Cookies, Complete Programs, Databases
This is a very simple BBS that uses MySQL
Categories : MySQL, Databases, Complete Programs, PHP
DBE - Database Expander: Edit PostgreSQL individual database tables online via your Web browser!
Categories : PostgreSQL, Complete Programs, Databases, PHP Classes, PHP
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
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
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
complete, simple, working example of a login screen/system using php functions, cookies, and a mysql database for begginers.
Categories : Authentication, Complete Programs, PHP, MySQL, Databases
AITSH Statistics
Categories : Complete Programs, Databases, HTML and PHP, Sessions, PHP
Tropicalm Genetree Family (MySQL based family tree)
Categories : PHP, Interfaces, Databases, MySQL, Complete Programs
phpMyAdmin is intended to handle the adminstration of MySQL over the web.
Categories : Databases, MySQL, Complete Programs, PHP
This program will take data from a user via a web based form, validate it, show it to the user for re-validation, and finally insert it into the database. Plenty of sanity checking on the fields in the form.
Categories : MySQL, HTML and PHP, PHP, Complete Programs, Databases