MyQuotes - Ihr persönlicher Aktienrechner
The File pdo_access.inc.php contains a class also called pdo_access. It must be instantiated, pdo_access does not work in a static way. The constructor requires at least one argument, a dsn (Data Source Name), optional a username and a password to connect to the specified database.
Sourceforge Projectsite & Download
Corvent Ltd. is our company which made the development of this library possible
PHP 5.1
topThe simple case, an sqlite File as Database
Connecting to a mySQL Database
This will probably be the most used method. It just takes an sql query and returns the result from the query as numeric array of the matching records. The records are Hashtables haveing the columnname as key and the value as value.
| employees | |
|---|---|
| 0 | id 1 name smith firstname bill salery 60000 department development |
| 1 | id 2 name oklahoma firstname joe salery 45000 department finance |
| 2 | id 6 name simpson firstname homer salery 24000 department security |
| 3 | id 8 name simpson firstname lisa salery 50900 department development |
| 4 | id 9 name simpson firstname marge salery 46000 department finance |
| 5 | id 13 name simpson firstname bart salery 32454 department finance |
| 6 | id 14 name newbie firstname john salery 45463 department sales |
If you are not intrested in a numeric array you may define a unique column to use for the keys. It may be passed in the secound optional argument.
| employees | |
|---|---|
| 1 | name smith firstname bill salery 60000 department development |
| 2 | name oklahoma firstname joe salery 45000 department finance |
| 6 | name simpson firstname homer salery 24000 department security |
| 8 | name simpson firstname lisa salery 50900 department development |
| 9 | name simpson firstname marge salery 46000 department finance |
| 13 | name simpson firstname bart salery 32454 department finance |
| 14 | name newbie firstname john salery 45463 department sales |
The column used as key needs not to be numeric, but unique, if its not you may get a result like this:
| employees | |
|---|---|
| smith | id 1 firstname bill salery 60000 department development |
| oklahoma | id 2 firstname joe salery 45000 department finance |
| simpson | id 13 firstname bart salery 32454 department finance |
| newbie | id 14 firstname john salery 45463 department sales |
This method is nice whereever you need an association from e.g. an id to a name
| employees | |
|---|---|
| 1 | smith |
| 2 | oklahoma |
| 6 | simpson |
| 8 | simpson |
| 9 | simpson |
| 13 | simpson |
| 14 | newbie |
The first column given will be the key of your hashtable (here id). If you have exacly 2 columns in your query the second one will be the value.
These results can be nicely transformed into a HMTL-Selector Element
topThis function is suitable to get a specific record from
| employee id 6 | |
|---|---|
| id | 6 |
| name | simpson |
| firstname | homer |
| salery | 24000 |
| department | security |
If no records match the method returns false
If more than one records match, by default the method returns false too (to indicate that maybe the database has not that counsistency that you assume), you may change this behaviour by passing the second argument "allowMultipleMatch" the value true, than you get the first record as result
| Multiple match, ingnoring multiple Result | |
|---|---|
| id | 6 |
| name | simpson |
| firstname | homer |
| salery | 24000 |
| department | security |
Nice if you are intrested in a valueList of a column
| all ids | |
|---|---|
| 0 | 1 |
| 1 | 2 |
| 2 | 6 |
| 3 | 8 |
| 4 | 9 |
| 5 | 13 |
| 6 | 14 |
Nice if you are intrested in one single Cell-value
pdo_access provides also methods to insert, update and delete records
topinsertValues($tableName, $values);
The return-value is the new generated id for the new recort (if there is an auto-increment column) otherwise it's the number of affected rows, or false in case of faliure
All Table Content now:
| employees | |
|---|---|
| 0 | id 1 name smith firstname bill salery 60000 department development |
| 1 | id 2 name oklahoma firstname joe salery 45000 department finance |
| 2 | id 6 name simpson firstname homer salery 24000 department security |
| 3 | id 8 name simpson firstname lisa salery 50900 department development |
| 4 | id 9 name simpson firstname marge salery 46000 department finance |
| 5 | id 13 name simpson firstname bart salery 32454 department finance |
| 6 | id 14 name newbie firstname john salery 45463 department sales |
| 7 | id 15 name newbie firstname john salery 45463 department sales |
updateValues($tableName, $condition, $values);
The return value represents the number of changed rows, or fals on failure
All Table Content now:| employees | |
|---|---|
| 0 | id 1 name smith firstname bill salery 60000 department development |
| 1 | id 2 name oklahoma firstname joe salery 45000 department finance |
| 2 | id 6 name simpson firstname homer salery 24000 department security |
| 3 | id 8 name simpson firstname lisa salery 50900 department development |
| 4 | id 9 name simpson firstname marge salery 46000 department finance |
| 5 | id 13 name simpson firstname bart salery 32454 department finance |
| 6 | id 14 name newbie firstname john salery 45463 department sales |
| 7 | id 15 name newbie firstname john salery 45463 department sales |
delete($tableName, $condition);
For security reasons the condition must not be an empty string, to delete all records you may pass something like "1=1" as codition
return-value is the number of deleted records
All Table Content now:| employees | |
|---|---|
| 0 | id 1 name smith firstname bill salery 60000 department development |
| 1 | id 2 name oklahoma firstname joe salery 45000 department finance |
| 2 | id 6 name simpson firstname homer salery 24000 department security |
| 3 | id 8 name simpson firstname lisa salery 50900 department development |
| 4 | id 9 name simpson firstname marge salery 46000 department finance |
| 5 | id 13 name simpson firstname bart salery 32454 department finance |
| 6 | id 14 name newbie firstname john salery 45463 department sales |
pdo_access provides 3 additional function to get simple statistic information from a table
topcountRecords($tableName[, $condition]);
This is a shortcut for "getSQLResultFirstCell("SELECT COUNT(*) FROM $tableName WHERE $condition");"
topgetDistinctValues($tableName, $column, [, $condition]);
| departments | |
|---|---|
| 0 | development |
| 1 | finance |
| 2 | sales |
| 3 | security |
This is a shortcut for "getSQLResultFirstCol("SELECT DISTINCT($column) FROM $tableName WHERE $condition");"
topcountDistinctValues($tableName, $column, [, $condition]);
This is a shortcut for "getSQLResultFirstCell("SELECT CONT(DISTINCT($column)) FROM $tableName WHERE $condition");"