introducti̇on

needmoreneedmoreΔιαχείριση Δεδομένων

28 Νοε 2012 (πριν από 4 χρόνια και 7 μήνες)

187 εμφανίσεις


INTRODUCTİON...

P
HP is a wonderful language for building dynamic web pages.
Unfortunately, PHP's database access functions are not standardised.
Every database extension uses a different and incompatibile API. This
creates a need for a database class libr
ary to hide the differences between
the different databases (encapsulate the differences) so we can easily
switch databases.


ADOdb stands for Active Data Objects Data Base. We currently support
MySQL, PostgreSQL, Interbase, Informix, Oracle, MS SQL 7, Fo
xpro,
Access, ADO, Sybase, DB2 and generic ODBC. The Sybase, Informix and
PostgreSQL drivers are community contributions. We hope more people will
contribute drivers to support more databases.


Unique Features of ADOdb

Easy for Windows programmers to under
stand. Makes porting ASP code to
PHP easy because many of the conventions are similar to Microsoft's ADO.

We provide support code to handle inserts and updates which can be
adapted to multiple databases quickly. Methods are provided for date
handling, str
ing concatenation and string quoting characters for differing
databases.

A metatype system is built in so that we can figure out that types such as
CHAR, TEXT and STRING are equivalent in different databases.

Easy to port because all the database dependa
nt code are stored in stub
functions. You do not need to port the core logic of the classes.

SQL to popup menu (<SELECT>) support included

PHP4 Session support.


2



WHAT IS NEW


In ADOdb 3.20, we have added a new api for creating tables and indexes.
Th
is is still alpha quality, but you can read docs and test it out in
adodb/tests/test
-
datadict.php. Currently only mysql, postgresql, mssql
(odbc, ado, native), and oci8 (oracle) supported.



// First create a normal connection

$db
-
>NewADOConnection('mysql'
);

$db
-
>Connect(...);


// Then create a data dictionary object, using this connection

$dict = NewDataDictionary($db);


// We demonstrate creating tables and indexes

$tabname = 'atable';

$fldarray = array(

array('name', 'C', '32', 'key'),

array('price', 'N'
, '7.2', 'default' => 0, 'notnull')

);

$taboptarray = array('mysql'=>'TYPE=ISAM', 'oci8'=>'TABLESPACE
USERS');


// return an array of sql strings

$sqlarray = $dict
-
>CreateTableSQL($tabname, $fldarray, $taboptarray);

$dict
-
>ExecuteSQLArray($sqlarray);


$sql
array = $dict
-
>CreateIndexSQL('idxname', 'tabname', 'col1,col2');

$dict
-
>ExecuteSQLArray($sqlarray);



This will generate the sql:


CREATE TABLE atable (

name VARCHAR(32) NOT NULL,

price NUMERIC(7,2) NOT NULL DEFAULT 0,

PRIMARY KEY (name)

)TYPE=ISAM


and


CREATE INDEX idxname ON tabname (col1,col2)


Also we have done extensive testing with $ADODB_COUNTRECS and
have cleaned up some bugs when you set it to false, disabling record
counting emulation. My benchmarks reveal that there is an overhead of 20
-
30
% for databases that do not support native record counts such as oracle,
mssql, etc when $ADODB_COUNTRECS=true.


Lastly, we now use mysql_real_escape_string (php 4.3 or later) and
pg_escape_string (php 4.2 or later) for qstr(), which is needed for multibyt
e
languages such as Chinese/Japanese.




ChangeLog:


<p>Added new Data Dictionary classes for creating tables and indexes.
Warning
-

this is very much alpha quality code.

The API can still change. See adodb/tests/test
-
datadict.php for more info.


<p>We now

ignore $ADODB_COUNTRECS for mysql, because PHP
truncates incomplete recordsets when mysql_unbuffered_query() is called a
second time.


<p>Now postgresql works correctly when $ADODB_COUNTRECS = false.


<p>Changed _adodb_getcount to properly support SELECT
DISTINCT.


<p>Discovered that $ADODB_COUNTRECS=true has some problems with
prepared queries
-

suspect PHP bug.


<p>Now GetOne and GetRow run in $ADODB_COUNTRECS=false mode
for better performance.


<p>Added support for mysql_real_escape_string() and pg_esca
pe_string()
in qstr().


<p>Added an intermediate variable for mysql _fetch() and MoveNext() to
store fields, to prevent overwriting field array with boolean when
mysql_fetch_array() returns false.


<p>Made arrays for getinsertsql and getupdatesql case
-
inse
nsitive.
Suggested by Tim Uckun" tim#diligence.com


Topic: Re:ADOdb 3.20 released
-

table creation api

author: Martin Dougiamas created: 14
-
03
-
2003 03:28:52 AM

This table creation stuff is going to be fantastic
-

I hope it'll save me a lot of
headaches i
n future (currently I'm maintaining database
-
specific SQL files
for my application).


Are there any plans yet to add other operations such as
adding/deleting/altering table columns? That would pretty much complete
the feature
-
set that I need from ADOdb.


C
heers,

Martin


Topic: Re:ADOdb 3.20 released
-

table creation api

author: Martin Dougiamas created: 14
-
03
-
2003 03:37:19 AM

My apologies, I just did what I should have done before posting, which was
to check your code!


And I see you've implemented AddCol
umnSQL and AlterColumnSQL
functions. Yay, well done!


Unfortunately, I see AlterColumnSQL is not yet implemented for
PostgreSQL (because PostgreSQL itself doesn't support it
-

Boo!!).


There is a way to do it, though
-

so perhaps these methods will help f
or a
future version of ADOdb:



3




Examples

MySQL Usage:

include('adodb.inc.php'); include('tohtml.inc.php');

$conn = &ADONewConnection('mysql');

$conn
-
>PConnect('localhost','userid','password','database');

$rs = $conn
-
>Execute('select * from table');

rs2html($rs); /* recordset to html table */


MySQL Cached Recordset Usage:



include('adodb.inc.php'); include('tohtml.inc.php');

$ADODB_CACHE_DIR = '/usr/local/adodbcache';

$conn = &ADONewConnection('mysql');

$conn
-
>PConnect('localhost','userid','passwo
rd','database');

$rs = $conn
-
>CacheExecute(15, 'select * from table'); # cache 15 secs

rs2html($rs); /* recordset to html table */


ODBC Usage:


include('adodb.inc.php'); include('tohtml.inc.php');

$conn = &ADONewConnection('odbc');

$conn
-
>PConnect($dsn
); # userid, passwd optional

$rs = $conn
-
>Execute('select * from table');

rs2html($rs); /* recordset to html table */


Oracle Usage:


include('adodb.inc.php'); include('tohtml.inc.php');

$conn = &ADONewConnection('oracle');/* Oracle 8, use 'oci8' */

$c
onn
-
>PConnect('','scott','tiger');

$rs = $conn
-
>Execute('select * from table');

rs2html($rs); /* recordset to html table */


You might need to putenv('ORACLE_HOME=...') above, and pass a 4th
parameter to PConnect(), which is the Oracle connection string.

Oracle SelectLimit Usage:




include('adodb.inc.php'); include('tohtml.inc.php');

$conn = &ADONewConnection('oracle');/* Oracle 8, use 'oci8' */

$conn
-
>PConnect('','scott','tiger','TNSName');

$nrows = 100; # retrieve only first 100 records

$offset = 200;

# skip first 200 records

$rs = $conn
-
>SelectLimit('select * from table',$nrows,$offset);

rs2html($rs); /* recordset to html table */


Interbase Usage:


include('adodb.inc.php'); include('tohtml.inc.php');

$conn = &ADONewConnection('ibase');

$conn
-
>PCo
nnect('c:
\
ibase
\
employee.gdb','sysdba','masterkey');

$rs = $conn
-
>Execute('select * from table');

rs2html($rs); /* recordset to html table */


Some users report you might need to use:

$db
-
>PConnect('localhost:c:
\
ibase
\
employee.gdb', "sysdba", "masterkey")
;





B
u ödevin size hayırlı olma temennisiyle


www.gencbilim.com