PHP Classes

File: Zebra_Database.php

Recommend this page to a friend!
  Classes of Stefan Gabos  >  Zebra Database  >  Zebra_Database.php  
File: Zebra_Database.php
Role: Class source
Content type: text/plain
Description: Class source
Class: Zebra Database
MySQL database access wrapper library
Author: By
Last change: Updated version number
Fixed an issue where PHP would trigger a notice when the library was used as a static class

Thanks to Andrew Rumm!
Fixed more instances where PHP 5.5+ would trigger some notices
Fixed a bug where PHP 5.5+ would trigger a warning when using memcache

...thanks to Andrew Rumm for reporting
More fixes for warning when no queries are run
More fixes for warnings when no queries are run
Fixed an issue in the destructor

...which would trigger a warning message if there were no queries
Added method for getting the currently selected db

...thanks to Stijn for suggesting
Minor fixes
Added notification_address and notifier_domain checks before sending email notifications.
Fixed a bug with the log files

...where the log files were recreated at each execution rather than
being updated; thanks to Eike Broda
Fixed a bug in the library's destructor

...where mysqli_free_result would trigger a notice in your server's log
files if the result was not a mysqli result set (as it could also be a
boolean for queries that do not return anything or even unset when no
queries were run); thanks to Eike Broda!
Some documentation updates
Simpler usage of WHERE-IN conditions

...thanks to primeinc
added support for WHERE `column` IN ?

Also updated debug console display to reflect changes in 8972c81
Update version number
Update revision date
realpath for auto resource_path

Recently switched to a symlinked doc root and noticed an interesting problem, `dirname(__FILE__)` resolves to the real resolved path (not the symlink) and `$_SERVER['DOCUMENT_ROOT']` resolves to the unresolved symlink path. So if your paths don't have the same amount of characters it causes a problem.
The `DIRECTORY_SEPARATOR` doesn't seem to be needed, at least on my dev server it adds an extra / between domain and path but it doesn't do anything bad so I figured I'd leave it in case its needed elsewhere.
Updated revision date
Fixed port and socket not used even if set

Thanks to Nam Trung for reporting
Fix backlashes injected by mysqli escape

I was trying to insert some binary data with null chars and ran into a weird problem, tracked it down to preg_replace requiring backslashes to be doubled if used inside of replacements.
```php
$original = "string\x00with\x00nulls\x00andDollar\\$23";
$replacements = $db->escape($original);
$randomstr = '/MD5VALUE/';
echo "Original PRE-REPLACED value: $original" . PHP_EOL;
echo "Escaped PRE-REPLACED value: $replacements" . PHP_EOL;
$sql = "MD5VALUE";
$replacements = '\'' . preg_replace('/\$([0-9]*)/', '\\\$$1',$replacements) . '\'';
$sql = preg_replace($randomstr, $replacements, $sql,1);
echo 'Currently inserted: ' . $sql . PHP_EOL;

$sql = "MD5VALUE";
$replacements = '\'' . preg_replace(array('/\\\\/','/\$([0-9]*)/'), array('\\\\\\\\','\\\$$1'), $db->escape($original)) . '\'';
$sql = preg_replace($randomstr, $replacements, $sql, 1);
echo 'Fixed: ' . $sql . PHP_EOL;
```
Output:
```
Original PRE-REPLACED value: stringwithnullsandDollar\$23
Escaped PRE-REPLACED value: string\0with\0nulls\0andDollar\\$23
Currently inserted: 'stringMD5VALUEwithMD5VALUEnullsMD5VALUEandDollar\$23'
Fixed: 'string\0with\0nulls\0andDollar\\$23'
```
Line 3111 also uses `preg_replace('/\$([0-9]*)/', '\\\$$1',$match[0])` but doesn't escape it with `mysqli_real_escape_string()` so I figured that didn't need to be changed. My problem was with the null char but I'm pretty sure this would have effected other things with backslashes, like \n or \r.
Fixed bug with dlookup & friends and caching
Setting memcache_compressed to TRUE had no effect

Thanks to Andrew Rumm for reporting!
Fixed a bug with CSS/JS when port is not 80

The library would not correctly look for the CSS and JS files (used by
the debug console) when using a port other than 80; thanks to Gabriel
Moya!
Result sets can now also be stored in sessions
Fixed a typo in the comments
Minor maintenance of code from latest pull req.
Updated SELECT columns

Backwards compatible, columns actually are wrapped in grave accents now,
$columns can now be accepted as an indexed array (no keys) to
standardize column and columns behavior
Fixed disable_warning not working
Added user ability to change resource path

Backwards compatible, allows users to move scripts and stylesheets to
their own locations
Fixed a bug in the "get_tables" method

...which would trigger warning messages; thanks to Stefan L for
reporting
Fixed a typo in the comments

Thanks to Dan for spotting it!
Updated last revision's date
Added a new "memcache_key_prefix"

...this allows separate caching of the same queries by multiple
instances of the libraries on the same memcache server, or the library
handling multiple domains on the same memcache server; thanks to
primeinc!
Merge pull request #6 from primeinc/master

Added memcache key prefix
fixed small typo in insert_bulk()
Added memcache key prefix

This allows the same script to be run on different domains on the same
memcache server.
Fixed a bug with the connection credentials

...which were stored in a public property rather than a private one;
thanks to etb09
Correct indentation in log files

...regardless of language file
Daily/Hourly Logfile, Fix of Logfile

As the log.txt, generated by write_log(), becomes very big i've added a possibility to create a new log file each day and each hour.

Also I've fixed a small bug with the backtrace info. These lines were without a value.
Updated last revision date
Fixed a problem with insert_bulk

php 5.4.16
Correct use of insert_bulk ($a = array(array("",""), array("",""));) causes this error:
'Problem "Strict standards: Only variables should be passed by reference"'
The solution is based on comments on stackoverflow (http://stackoverflow.com/q/2354609)
Updated version number
Fixed a minor issue that could trigger a warning
Table names are now enclosed in grave accents

...for all the methods that take a table name as argument: dcount,
delete, dlookup, dmax, dsum, get_table_columns, insert, insert_bulk,
insert_update, select, truncate and update; this allows working with
tables having special characters in their name
Removed automatic closing of the connection

...as this could interfere with your custom session handler
Initial GitHub release
Date: 5 years ago
Size: 177,653 bytes

You need to be a registered user and login to get this file.

1,588,257 PHP developers registered to the PHP Classes site.
Be One of Us!

Login Immediately with your account on:

FacebookGmailHotmailStackOverflowGitHubYahoo
For more information send a message to info at phpclasses dot org.