Zebra_Database, a MySQL database wrapper library built around PHP’s mysqli extension

Get the latest updates on this PHP library via RSS

Zebra_Database it is an advanced, compact (one-file only) and lightweight database wrapper built around PHP’s MySQLi extension. It provides methods for interacting with MySQL databases that are more secure, powerful and intuitive than PHP’s default ones.

It supports transactions and provides ways for caching query results either by saving cached data on the disk, or by using memcache.

The class provides a comprehensive debugging interface with detailed information about the executed queries: execution time, returned/affected rows, excerpts of the found rows, error messages, etc. It also automatically EXPLAIN‘s each SELECT query (so you don’t miss those keys again!).

It encourages developers to write maintainable code and provides a better default security layer by encouraging the use of prepared statements, where parameters are automatically escaped.

Zebra_Database‘s code is heavily commented and generates no warnings/errors/notices when PHP’s error reporting level is set to E_ALL.

In the image below you see the debugger in its default state: minimized and in the top-right corner of the page. It shows the number of successful queries and the number of unsuccessful queries:

Zebra_Database, Debug Console

Once the debug console is clicked, it will maximize and show a menu from where successful queries, unsuccessful queries and global variables can be viewed:

Zebra_Database, Debug Console

If the “successful queries” tab is clicked, the debug console will show detailed information about all the successful queries that have been run: the syntax highlighted queries, the execution time (in milliseconds) and how much (in percents) it represents of the total execution time, the number of returned/affected rows (for SELECT queries this can be clicked to show the actual returned rows), a link to see the query EXPLAIN-ed (only for SELECT queries), and a link to see backtracing information.

Zebra_Database, Debug Console

For SELECT queries, clicking on “returned rows” shows a table with the actual records returned by the query:

Zebra_Database, Debug Console, image 4

For SELECT queries, clicking on “explain” shows the query EXPLAIN-ed:

Zebra_Database, Debug Console, image 5

For all successful queries, clicking on “backtrace” shows a table with information on what files and functions lead to the displayed query:

Zebra_Database, Debug Console, image 6

If there is an unsuccessful query, the debug console will open automatically to the respective query and besides the query will show the message returned by the MySQL server and backtracing information to easily find from what part of your code the query originated:

Zebra_Database, Debug Console, image 7

The images above are screen shots of what you’d get when running the example file available in the download-able package. The example uses the world database available on MySQL’s website.

The icons in the debug console are created by pixel-mixer.com.

Top

Features review

  • offers lots of powerful methods for easier interaction with MySQL
  • provides a better security layer by encouraging the use of prepared statements, where parameters are automatically escaped
  • provides a very detailed debugging interface with lots of useful information about executed queries; it also automatically EXAPLAIN’s each SELECT query
  • supports caching of query results to disk or to a memcache server
  • has comprehensive documentation
  • code is heavily commented and generates no warnings/errors/notices when PHP’s error reporting level is set to E_ALL

Top

Requirements

PHP 5+ with the mysqli extension activated, MySQL 4.1.22+

For using memcache as caching method, PHP must be compiled with the memcache extension and, if memcache_compressed property is set to TRUE, needs to be configured with –with-zlib[=DIR]

Top

Installation

Download the latest version, unpack it, and put it in a place accessible to your scripts.

Top

How to use

Connect to a database

<?php

require 'path/to/Zebra_Database.php';

$db = new Zebra_Database();

// turn debugging on
$db->debug = true;

$db->connect('host', 'username', 'password', 'database');

// code goes here

// this should always be present at the end of your scripts;
// whether it should output anything should be controlled by the $debug property
$db->show_debug_console();

?>

A SELECT statement

<?php

// $criteria will be escaped and enclosed in grave accents, and will
// replace the corresponding ? (question mark) automatically
$db->select(
    'column1, column2',
    'table',
    'criteria = ?',
    array($criteria)
);

// after this, one of the "fetch" methods can be run:

// to fetch all records to one associative array
$records = $db->fetch_assoc_all();

// or fetch records one by one, as associative arrays
while ($row = $db->fetch_assoc()) {
    // do stuff
}
?>

An INSERT statement

<?php

$db->insert(
    'table',
    array(
        'column1' => $value1,
        'column2' => $value2,
    )
);

?>

An UPDATE statement

<?php

// $criteria will be escaped and enclosed in grave accents, and will
// replace the corresponding ? (question mark) automatically
$db->update(
    'table',
    array(
        'column1' => $value1,
        'column2' => $value2,
    ),
    'criteria = ?',
    array($criteria)
);

?>

Top

Download

version 2.8.5
If you find this library to be useful to you, you can support the author by donating a small amount via PayPal:

Zebra_Database is distributed under the LGPL.

In plain English, this means that you have the right to view and to modify the source code of this software, but if you modify and distribute it, you are required to license your copy under a LGPL-compatible license, and to make the entire source code of your derivation available to anybody you distribute the software to.

You also have the right to use this software together with software that has different licensing terms (including, but not limited to, commercial and closed-source software), and distribute the combined software, as long as state that your software contains portions licensed under the LGPL license, and provide information about where the LGPL licensed software can be downloaded.

If you distribute copies of this software you may not change the copyright or license of this software.


You may also like:

Top

Documentation

Documentation Become a ninja.
Read the comprehensive documentation.
Top

Changelog

Click on a version to expand/collapse information.

version 2.8.5 (November 12 2014)
  • result sets can now also be cached in sessions
  • users can now change resource paths, allowing users to move scripts and stylesheets to whatever locations; thanks to Joseph Spurrier
  • column names for the select() method can now be given as an array (recommended) and will be automatically enclosed in grave accents; ; thanks to Joseph Spurrier
  • fixed a bug with determining the path to the library’s CSS and JavaScript when using symlinks; thanks to primeinc
  • fixed a bug with backslashes in the replacement strings; thanks to primeinc
  • fixed a bug in the “get_tables” method which would trigger warning messages; thanks to Stefan L for reporting
  • fixed bug with dlookup method & friends and caching;
  • fixed composer.json and the library is now correctly working with Composer’s autoloader; thanks to Joseph Spurrier
  • fixed a bug where setting the “disable_warnings” property to true would not actually disable warning; thanks to Joseph Spurrier
  • fixed a bug where setting the “memcache_compressed” property to TRUE had no effect; thanks to Andrew Rumm
  • fixed a bug with CSS/JS when port is not 80 where 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!
  • fixed a bug where port and socket were not used even if set; thanks to Nam Trung
  • fixed some typos in comments
version 2.8.4 (December 22 2013)
  • added a new “memcache_key_prefix” property; 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;
  • fixed a bug with the insert_bulk method; thanks to Guillermo;
version 2.8.3 (October 10 2013)
  • fixed a bug with the connection credentials which were stored in a public property rather than a private one; thanks etb09
  • fixed a bug with the output generated by the “write_log” method; thanks etb09
  • fixed a bug where the “insert_bulk” and “write_log” methods would trigger a “strict standards” warning in PHP 5.4+; thanks etb09
  • fixed a minor issue that could cause the library to trigger a warning (only when debugging was on)
  • log files can now be generated by date and hour; thanks etb09
  • entries in log files now have correct indentation regardless of the used language file
  • added German translation; thanks etb09
version 2.8.2 (August 24 2013)
  • 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;
  • minor performance optimizations in the debug console’s JavaScript code
version 2.8.1 (August 02, 2013)
  • fixed an issue introduced in the previous release generated by the changing of the arguments order in the “query” method and which affected some of the library’s methods; thanks ziggy;
  • inversed the order of last 2 arguments of the “select” method (“calc_rows” now comes before “highlight”); if you were using this argument make sure to addapt your code; thanks Prathamesh Gharat;
  • fixed a bug where when setting a query to be highlighted the debugging console would actually open and show the respective query *only* if the library’s “minimize_console” attribute was set to FALSE; now it will work either way;
  • the “connect” method has 2 new arguments: “port” and “socket”; because of this, the “connect” argument is now the last argument of the method so make sure you update your code if you have to; thanks Corey;
  • proper declaration private and public variables;
  • some performance tweaks;
  • fixed some issues in the documentation; thanks Mark;
  • the project is now available on GitHub and also as a package for Composer;
version 2.8 (March 15, 2013)
  • dropped support for PHP 4; minimum required version is now PHP 5;
  • dropped support for PHP’s mysql extension, which is officially deprecated as of PHP v5.5.0 and will be removed in the future; the extension was originally introduced in PHP v2.0 for MySQL v3.23, and no new features have been added since 2006; the library now relies on PHP’s mysqli extension;
  • removed the “is_new” argument from the “connect” method as it’s not needed by the mysqli extension; this means that “connect” is now the 5th argument and that this may break your code so be sure to update accordingly;
  • inversed the order of last 2 arguments of the “query” method (“calc_rows” now comes before “highlight”); if you were using this argument make sure to addapt your code or risk opening a black-hole;
  • changed an instance of mktime() to time() as it was giving a “PHP Strict Standards” error since PHP 5.3.0;
  • fixed a bug when specifying custom paths for the “write_log” method ; thanks Andrei Bodeanschi;
  • fixed an issue where setting “cache_path” to a path without trailing slash would break the script;
  • fixed an issue where setting the caching time to 0 would still create (empty) cache files;
  • the JS and CSS files used by the debugger window are now loaded “protocol-less” in order to solve those mixed-content errors; thanks to Mark Bjaergager
  • tweaked the CSS file a bit
version 2.7.3 (July 16, 2012)
  • the library now tries to write errors to the system log (if PHP is configured so; read more here) when the “debug” property is set to FALSE (as when the “debug” property is set to TRUE the error messages are reported in the debug console);
  • the library will now show a warning message in the debug console if the “memcache” extension is loaded but it is not used;
  • cached data is now gzcompress-ed and base64_encoded which means cached data is a bit more secure and a bit more faster to load; thanks to PunKeel for suggesting this a while ago;
  • changed (again!) the order of the arguments for the “select” method – “limit” now comes before “order”; note that this update made the select() method backward incompatible and that you will have to change the order of the arguments for this to work!
  • added a small example on how to use caching through memcache; see the documentation for the “caching_method” property;
version 2.7.2 (April 07, 2012)
  • fixed a bug that most likely appeared since 2.7, where the “seek” method (and any method relying on it, like all the “fetch” methods) would produce a warning in the debug console if there were no records in the sought resource;
  • fixed a bug where NULL could not be used in the “replacements” array of a query; thanks to בניית אתרים;
version 2.7.1 (February 10, 2012)
  • the select() method took arguments in a different order than specified in the documentation; thanks to Andrei Bodeanschi; note that this update made the select() method backward incompatible and that you will have to change the order of the arguments for this to work!
  • fixed a bug where the update() and insert_update() methods were not working if in the array with the columns to update, the INC() keyword was used with a replacement marker instead of a value, and the actual value was given in the replacements array; thanks to Andrei Bodeanschi;
  • fixed a bug where the insert_update() method was not working when the only update field used the INC() keyword; the generated query contained an invalid comma between UPDATE and the field name; thanks to Allan;
version 2.7 (January 07, 2012)
  • added support for caching query results using memcache. thanks to Balazs for suggesting it a while ago, and to Ovidiu Mihalcea for introducing me to memcache;
  • fixed a bug where the script would crash if the object was instantiated more than once and the language method was being called for each of the instances; thanks to Edy Galantzan;
  • completely rewritten the dlookup method which was not working correctly if anything else than a comma separated list of column names was used (like an expression, for example); thanks to Allan;
  • the “connect” method can now take an additional argument instructing it to connect to the database right away rather than using a “lazy” connection;
  • fixed a bug where some of the elements in the debug console were incorrectly inheriting the page’s body color
version 2.6 (September 03, 2011)
  • changed the name of “get_columns” method to “get_table_columns” as it returned the number of columns in a given table, and added a new “get_columns” method which takes as argument a resource and returns the number of columns in the given resource;
  • some documentation clarifications
version 2.5 (July 02, 2011)
  • a new method is now available: “get_link” which returns the MySQL link identifier associated with the current connection to the MySQL server. Why as a separate method? Because the library uses “lazy connection” (it is not actually connecting to the database until first query is executed) there’s no link identifier available when calling the connect method.
  • a new argument is now available for the insert and insert_bulk methods which allows the creation of INSERT IGNORE queries which will skip records that would cause a duplicate entry for a primary key.
  • the default value of the “debug” property was set to FALSE
version 2.4 (June 20, 2011)
  • fixed a bug with the insert_bulk method (thanks to Edy Galantzan for reporting)
  • added a new method: table_exists which checks to see if a table with the name given as argument exists in the database
  • the select method now also accepts limit and order arguments; due to this change, this method is not compatible with previous versions (thanks to Monil for suggesting this)
  • some documentation refinements
version 2.3 (April 15, 2011)
  • fixed a bug where the script would generate a warning if the “update” method was called with invalid arguments;
  • changed how the insert_bulk method needs to receive arguments, making it more simple to use
version 2.2 (March 05, 2011)
  • fixed a bug where the “select” method war returning a boolean value rather than a resource (thanks to Monil);
  • the class now uses “lazy connection” meaning that it will not actually connect to the database until the first query is run;
  • the debug console now shows also session variables;
  • the “show_debug_console” method can now be instructed to return output rather than print it to the screen;
  • the highlighter now highlights more keywords;
  • improved documentation for the “connect” method;
version 2.1 (January 27, 2011)
  • fixed a bug where the console inherited CSS properties from the parent application;
  • fixed some bugs in the JavaScript file that would break the code when parent application was running MooTools;
  • transactions are now supported;
  • added a new “insert_bulk” method which allows inserting multiple values into a table using a single query (thanks Sebi P. for the suggestion);
  • added a new “insert_update” method which will create INSERT statements with ON DUPLICATE UPDATE (thank Sebi P. for the suggestion);
  • enhanced the “update” method;
  • the debug console now shows a warning if no charset and collation was specified;
  • corrections to the documentation;
version 2.0 (January 21, 2011)
  • the entire code was improved and some of the properties as well as method names were changed and, therefore, this version breaks compatibility with earlier versions;
  • fixed a bug where the script would try to also cache action queries; thanks to Romulo Gomez;
  • fixed a bug in the “seek” method;
  • fixed a bug where on some configurations of Apache/PHP the script would not work;
  • fixed a bug where if there was a connection error or MySQL generated an error and the debug console was minimized, it would not be shown automatically;
  • fixed a bug where the “dlookup” method would not return escaped column names (i.e. `order`);
  • fixed a bug where the “found_rows” property was incorrect for cached queries;
  • fixed a bug where the debug console would improperly manage columns enclosed in ` (backtick);
  • fixed a bug that caused improper display of some strings in the debug console;
  • added a new method “select” – a shorthand for selecting queries;
  • added a new method “get_columns” – returns information about a given table’s columns;
  • added a new method “implode” – similar to PHP’s own implode() function, with the difference that this method “escapes” imploded elements and also encloses them in grave accents;
  • added a new method “set_charset” – sets the characters set and the collation of the database;
  • improved functionality of fetch_assoc_all() and fetch_obj_all() methods;
  • the debug console shows more information and in a much better and organized way;
  • rewritten the method for logging queries to a txt file making the output very easy to read;
  • dropped the XTemplate templating engine in order to improve speed; every aspect of the debug console can still be changed through the CSS file;
version 1.1.4 (July 24, 2008)
  • fixed a bug in the update() method when calling the method without the replacements argument;
version 1.1.3 (June 02, 2008)
  • fixed a bug that was causing an E_WARNING error when the caching folder could not be found;
  • fixed a minor issue that would trigger an error message if replacements were specified even though there was nothing to replace;
  • documentation is now clearer on how to define the caching folder;
version 1.1.2b (May 08, 2008)
  • fixed a huge bug in the highlighter when using $replacements;
  • fixed an issue where when calling a function/method that executes a method of the class by using of call_user_func_array() and friends, will produce a warning message due to the fact that, in such cases, the information returned by debug_backtrace() function is incomplete;
  • fixed a small issue in the template file that would produce an odd output when not having anything in the “messages” section;
version 1.1.2 (April 01, 2008)
  • fixed a bug where the debug console’s position could be influenced by the host application’s stylesheet;
  • fixed a minor bug in the “log_debug_info” method;
  • fixed a few minor bugs;
  • added new methods – “fetch_assoc_all” and “fetch_obj_all” which will fetch all the rows in a record set as an associative array or an array of objects respectively; “get_tables” – returns all the tables in the currently used database; “get_table_status” – returns useful information on all or only on specific tables; “optimize” – automatically optimizes tables that have overhead (unused, lost space);
  • full backtrace is now available in the debug console;
  • debug console is now a bit smarter and it does not highlight keywords in strings; also knows some more MySQL keywords;
  • more accurate reporting of duplicate queries;
  • better error reporting for when not being able to connect to the MySQL server or select a database;
version 1.1.1 (December 03, 2007)
  • fixed a bug in the close() method; thanks mokster;
  • some documentation refinements (thanks to Vincent van Daal);
version 1.1.0 (September 15, 2007)
  • fixed a bug where calling on a fetch method and on a cached query would send the script into an infinite loop;
  • improved the speed of the “dlookup” method by adding LIMIT to it; thanks to A.Leeming;
  • added some new methods: “close” (alias of mysql_close()), “log_debug_info” which writes debug information to a log file, and “seek” – alias of mysql_data_seek();
  • the “connect” method now returns the link identifier of the connection, which can be later used for closing the connection with the “close” method;
  • the “connect” method now returns the link identifier of the connection, which can be later used for closing the connection with the “close” method;
  • some documentation refinements; thanks Vincent van Daal;
  • completely rewritten debug console’s template file and stylesheet;
version 1.0.9 (May 30, 2007)
  • fixed a bug where the script would crash upon executing queries like SHOW TABLES, DESCRIBE, etc;
  • fixed a bug where due to a typo, no error message was shown if database could not be selected;
  • fixed a bug with $replacements containing apostrophes;
  • queries can now be cached;
  • new methods were added: “delete”, “truncate”, “insert” and “update” which are;
  • previously, all records returned by a SELECT query were shown in the debug console and that could crash the script if there were queries returning LOTS of rows; now there’s a new property called “showMaxRows” instructing the script on how many rows returned by SELECT queries to be shown in the debug console (thanks Dee S.);
  • the “debug” property is now TRUE by default
  • lots of code cleanups and documentation refinements
version 1.0.8 (January 28, 2007)
  • THIS VERSION BREAKS COMPATIBILITY WITH PREVIOUS ONES!
  • fixed a bug with $replacements containing question marks; thanks Joeri;
  • the debug console now shows backtracing information;
  • a new method was added: “fetch_obj” which is an alias of MySQL’s mysql_fetch_object function;
  • warnings of duplicate queries were incorrectly being displayed in the console window;
version 1.0.7 (November 24, 2006)
  • the debug console now also shows the result of EXPLAIN for SELECT queries;
  • queries can now be highlighted in debug console by setting the newly added $highlight argument for most of the methods;
  • the debug console now reports if two or more queries returned the same records (previously this feature was based on comparing the MySQL statements rahter than on the returned records);
  • a new “halt” method was added; this stops the execution of the script at the line where is called and displays the debug console (if the “debug” property is set to TRUE and the viewer’s IP address is in the allowed range set by the “debuggerIP” property);
  • fixed some Java Script issues with the debug console;
  • some code cleanup and documentation refinements;
version 1.0.6 (October 21, 2006)
  • fixed a bug where it was not possible to connect to two different databases by running two instances of this class in the same script;
  • fixed a bug where specifying two or more columns to be returned by the “dlookup” method would produce a warning if the column names were separated by a comma AND a space; there were no warnings if there was NO SPACE just one comma separating the column names;
  • fixed a bug where the “haltOnErrors” property was not implemented correctly and the script would actually be halted only on a few exceptional cases;
  • fixed a bug where the language could not be changed from the default one;
  • added a new method “setLanguage”;
  • the debug console can be instructed to appear only for a specific IP address;
  • the debug console now displays the actual returned rows for SELECT queries (thanks Zed);
  • each entry of each tab in the debug console can now be collapsed/expanded;
version 1.0.5 (October 02, 2006)
  • fixed a bug where the “insert_id()” method was not returning correct values (thanks arlc);
  • introduced a new boolean property called “haltOnErrors”; when set to TRUE the execution of the script will be halted upon fatal errors and the debug console will be shown (if the “debug” property is set to TRUE);
  • the debug console now highlights more keywords;
  • the debug console now shows MySQL keywords in upper case;
version 1.0.4 (September 03, 2006)
  • fixed a bug where the “affectedRows” property always returned 1;
  • fixed a bug where query execution time was incorrect in PHP 4;
  • fixed a bug where execution time was also computed for unsuccessful queries;
  • symbols are now highlighted in the debug console;
  • added a new method: “insert_id”, alias of mysql_insert_id() function;
  • the debug console now shows the number of returned rows for SELECT queries; this information is also available by reading the newly added “returnedRows” property;
  • the debug console can now be minimized both in real-time or by default by setting the newly added “minimizeDebugger” property;
  • the debug console shows queries in a more readable way;
  • the debug console now highlights more keywords;
  • tweaked various aesthetical aspects of the debug console;
  • debug information now can be logged to a file instead of being outputted to the screen;
version 1.0.3 (August 12, 2006)
  • the $_FILES and $_SESSION superglobals are now also shown in the debug console;
  • properties now have default values in PHP 4;
version 1.0.2 (August 10, 2006)
  • the debug console will now report if the same query was run more than once;
  • fixed a bug where the “_connected” method was reporting errors to the debug console; because it is a private method, it should report to the method that called it;
  • an example is now available in the downloadable package;
version 1.0.1 (August 05, 2006)
  • the “escape_string” method now escapes any values – in previous version it didn’t escape numbers;
version 1.0 (July 20, 2006)
  • initial release;

Top

223 responses to “Zebra_Database, a MySQL database wrapper library built around PHP’s mysqli extension”

Follow the comments via RSS
  • mamy, 2014-05-30, 21:22

    how we can select all the name of the column for the foreigne key in the balise …..

    Reply
  • John-O, 2014-09-09, 16:40

    I’ve finally switched from the old Phplib MySQL wrapper to Zebra_database. But I’m experiencing some strange performance problems. I’ve rewritted a simple class to use Zebra_database, but the code takes about 2 secs to execute (just a few queries). When I run the same code with the old wrapper it’s less than 1 sec. What can the reason be? Is it possible to implement the class “wrongly”?

    Reply
    • Stefan Gabos, 2014-09-09, 17:06

      Not really. The problem might be that you have debugging turned on and those queries return large amounts of data

  • Dave S, 2014-09-14, 20:46

    Do you know if anyone done a DataTables handler using Zebra_database?

    Reply
  • Roland, 2014-09-17, 16:16

    Hi great lib. Two quick questions:

    1. Are you still maintaining the codebase?
    2. Is this allowed:
    $db->query(‘
    SELECT
    *
    FROM
    users
    WHERE
    name LIKE ?
    ORDER BY surname DESC
    LIMIT ?, 3
    ‘, array((‘%’.$filter.’%’), 0), false, true);

    I’m talking about the ? for LIMIT. It causes an error as it gets enclosed in ”.

    Thanks again

    Reply
    • Stefan Gabos, 2014-09-24, 09:14

      I am still maintaining the library. That is not allowed as, indeed, that will be enclosed in quotes (although, I was thinking about leaving numeric values unenclosed)
      Until then, you can do something like

      $db->query('
      SELECT
      *
      FROM
      users
      WHERE
      name LIKE ?
      ORDER BY surname DESC
      LIMIT ' . $db->escape($value) . ', 3
      ', array(('%' . $filter . '%')), false, true);
  • Koen Thomeer, 2014-09-25, 23:46

    Is it possible to make the class act as a singleton? Like in http://www.ricocheting.com/code/php/mysql-database-class-wrapper-v3.
    It coulde be powerfull when integrating in functions, classes, …

    Reply
  • Dave S, 2014-10-04, 06:19

    I must be missing something, as this is so basic, but … how do I use MySQL functions as values for insert()/update()/etc? For example, using NOW() to update a datetime column?

    Reply
  • Dave S, 2014-10-04, 21:31

    Until I figure out how to pass “NOW()” as a value for an update() statement, I’m using query() instead. However, I need to execute SQL that looks like this:

    update table set str="what?" where id=3

    But having a ? anywhere in the column values causes the replacement of ‘id=?’ to fail. Is there some type of escaping that needs to happen? Tried the escape() function but it does nothing to question marks. Thanks!

    Reply
  • Mark, 2014-11-11, 15:48

    Hi Stefan
    I’m trying to use table_exists() but get an error – is this not supposed to be used like this:

    $q1 = $db->table_exists(‘database.table’);

    I’m trying to loop through all databases and figure out if there is a WordPress table wp_posts – but no luck so far.

    Best wishes :D

    Reply
  • Mark, 2014-11-11, 16:01

    Sorry – a typo!

    I get a BOOL(true) for any query using $db->table_exists() ?
    Could you provide an example how to use this function ?

    while($r=$db->fetch_assoc($q1)){
    $dbname = $r["Db"];
    $q2 = 1;
    echo $dbname .” “. var_dump($db->table_exists(‘$dbname.wp_posts’));
    }

    Reply