Hi!
> I've started work on a database abstraction module (written in C) and was
> wondering if anybody had any thoughts to add to mine in order to develop a
> good solution.
> The working name for this is the dbx-module.
> The dbx-module will become available under an Open Source license (not
> sure which one, I would be happy if it became a part of the php-cvs-tree,
> but I'll think on it) as soon as I have the points mentioned (way...)
> below implemented and tested.
> So, here is a description of how things stand at the moment...
>
>
> I currently have 4 functions that can do most things I want:
>
> dbx_connect(string module_name, string hostname, string username, string
> password)
> // returns a dbx_connection object or false on failure
> // checks if the given module is loaded, if so the db-functions of
> this
> // module are used
> A dbx_connection object that is returned by dbx_connect has the members
> $db->handle
> $db->module
> The handle member is the actual handle you get from e.g. a mysql_connect
> call and as such can be used in native mysql-functions (like mysql_close).
> The module member is for internal use by the dbx-module only.
>
> dbx_query(dbx_connection handle, string sql_statement, long flags)
> // returns a dbx_query_result object on a successful query that
> returns data
> // or true for a successful other query (insert, delete) or false on
> failure
> // flags can be used to alter the amoount of returned info
> A dbx_query_result object that is returned by dbx_query (if it returned
> data) has the members
> $q->handle
> $q->rows
> $q->cols
> $q->info['name'][column_index]
> $q->info['type'][column_index]
> $q->data[row_index][column_index | 'column_name']
> The handle member is the actual handle you get from e.g. a mysql_query
> call and as such can be used in native mysql-functions (like
> mysql_fetch_row).
> The rows member contains the number of rows returned
> The cols member contains the number of columns returned
> The info array holds field-information that can only be accessed
> associatively, currently only field-name and type. The flags used in a
> call to dbx_query determine the amount of info returned.
> The data array holds the complete rows x cols data returned from the
> query, and can be accessed by row-index (0..rows-1) and column-index
> (0..cols-1) or field-name. The flags used in a call to dbx_query could
> also be used to specify if you just want indexed columns, just associated
> columns or both.
>
> dbx_close(dbx_connection handle)
> // return true or false
>
> dbx_error(dbx_connection handle)
> // returns a string containing all error-messages from the last call
> to any other dbx_function (on the same connection)
>
> Current status of the dbx-module:
> The dbx_connect, dbx_query and dbx_close functions are implemented (and
> seem to work ok), dbx_error is next.
> The only database that is abstracted so far is MySQL, ODBC is next,
> MSSQLServer after that (these are the only db's I can actually test at the
> moment).
> Development is done on my windows-box now, but since it's all standard
> C-stuff it should compile on Linux too (which I'll try after dbx_error and
> ODBC implementation)
>
>
> So, if any of you with an interest in this could add your $0.02 we might
> even get to $1.00 :-)
>
> Cheerio, Marc.
>
>
>
>
> As an example of a piece of PHP-script that uses the dbx-module (connects,
> selects a db, executes an update query, displays all results (twice) from
> a select query, closes):
>
> <?php
>
> $dbname='MyDatabase';
> $id=5930;
> // connect
> $dbhandle = dbx_connect("mysql", "localhost", "", "");
> echo "<b>dbx_handle (from dbx_connect):</b> "; print_r($dbhandle);
> echo "<br>";
> echo "<p>";
> // execute queries
> $result = dbx_query($dbhandle, "use $dbname");
> if ($result==0) echo "No data returned, query failed\n<br>";
> if ($result==1) echo "No data returned, query succeeded\n<br>";
> $result = dbx_query($dbhandle, "update sys_update set
> info='blablabla'");
> if ($result==0) echo "No data returned, query failed\n<br>";
> if ($result==1) echo "No data returned, query succeeded\n<br>";
> echo '<p>';
> // select query
> $q = dbx_query($dbhandle, "select id, parentid, description from
> tbl_info where parentid={$id} and language=1 order by id");
> if ($q==0) echo "No data returned, query failed\n<br>";
> elseif ($q==1) echo "No data returned, query succeeded\n<br>";
> else {
> $rows=$q->rows;
> $cols=$q->cols;
> echo $q->handle . "<p>table dimension: {$q->rows} x
> {$q->cols}<br><table border=1>\n";
> echo "<tr>";
> for($col=0; $col<$cols; ++$col) {
> echo
> "<td>-{$q->info["name"][$col]}-<br>-{$q->info["type"][$col]}-</td>";
> }
> echo "</tr>\n";
> for($row=0; $row<$rows; ++$row) {
> echo "<tr>";
> for($col=0; $col<$cols; ++$col) {
> echo "<td>-{$q->data[$row][$col]}-</td>";
> }
> echo "</tr>\n";
> }
> echo "</table><p>\n";
> echo "table dimension: {$q->rows} x id, parentid,
> description<br><table border=1>\n";
> for($row=0; $row<$rows; ++$row) {
> echo "<tr>";
> echo "<td>-{$q->data[$row]["id"]}-</td>";
> echo "<td>-{$q->data[$row]["parentid"]}-</td>";
> echo "<td>-{$q->data[$row]["description"]}-</td>";
> echo "</tr>\n";
> }
> echo "</table><p>\n";
> }
> echo '<p>';
> // error reporting // this doesn't work yet, so a bogus string is
> returned
> echo '<b>dbx_error:</b> ' . dbx_error() . '</b><br>';
> echo '<p>';
> // close
> $result = dbx_close($dbhandle); // mysql_close($dbhandle->handle);
> works too!
> echo '<b>result of dbx_close:</b> ' . $result . '<br>';
> ?>
>
> Result of this script:
>
> dbx_handle (from dbx_connect): stdClass Object ( [handle] => Resource id
> #1 [module] => 1 )
> No data returned, query succeeded
> No data returned, query succeeded
> Resource id #2
> table dimension: 3 x 3
> -id- -parentid--description-
> -int- -int- -string-
> -1002- -5930- -Description X-
> -5931- -5930- -Info menu-
> -5937- -5930- -Info misc.-
> table dimension: 3 x id, parentid, description
> -1002- -5930- -Description X-
> -5931- -5930- -Info menu-
> -5937- -5930- -Info misc.-
> dbx_error: blobloblo
> result of dbx_close: 1
>
>
>
--
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]