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

Get the latest updates on this PHP library via RSS



You are currently browsing comments. If you would like to return to the full story, you can read the full entry here: “Zebra_Database, a MySQL database wrapper library built around PHP’s mysqli extension”.

241 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
  • Romeo, 2014-07-31, 08:25

    Salut, poti adauge si inca 2 functii:

    mysqli_errno

    si

    mysqli_free_result

    Astea imi mai lipsesc dar poate si alti le folosesc…

    Stiu ca mysqli_free_result nu prea se foloseste in general dar mai ajuta la aplicatii intensive

    Multumesc!

    Reply
    • Stefan Gabos, 2016-02-02, 13:04

      Adaugate. Multumesc!

  • 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

    • John-O, 2014-09-10, 11:55

      The problem was that I had written a small wrapper class that extended the Zebra_database, and did connect with correct credentials. So that I could write something like: $db = new myDb();, and have a ready and connected database object. But that must have added alot of overhead somehow. If I didn’t extend the class, then performance was great as expected.

  • 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);
  • Chris, 2014-09-24, 15:31

    Thank you for this great library!

    Due to my shared hosting settings I had to change __destruct() to prevent a warning. I don’t know if I did the right thing or if not freeing will give problems, but I also don’t like to initiate the database overnew for each query in my scripts. Perhaps I should?

    function __destruct()
        {

    // If you only connect to the database, $this->last_result = NULL // If you only connect and set charset, $this->last_result = BOOLEAN // // Don't free result in that case, otherwise, these give the following errors: // Warning: mysqli_free_result() expects parameter 1 to be mysqli_result, null/boolean given

    if ($this->last_result !== NULL && is_bool($this->last_result) == FALSE) {

    // frees the memory associated with the last result @mysqli_free_result($this->last_result);

    }

    }

    Reply
    • Stefan Gabos, 2016-01-11, 03:37

      This is now fixed. Thanks!

  • 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 πŸ˜€

    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
  • Jorge S, 2014-12-14, 01:49

    For Those , like me that use update ‘KEY’ => NULL
    Add this in the class ( function _build_sql(&$columns) )

    // if special INC() keyword is used
    elseif ( trim($value) == 'NULL' ) {
    $sql .= ($sql != '' ? ', ' : '') . '`' . $column_name . '` = NULL';
    unset($columns[$column_name]);
    }
    elseif (preg_match('/INC\((\-{1})?(.*?)\)/i', $value, $matches) > 0) {

    You can add more functions like for ex: ‘NOW()’
    Don’t Forget , if you upgrade the class to latest version you have to change this again or you will have a broken function πŸ™‚

    My 5 cents πŸ™‚ ,
    Until Stefan add’s a “special” array lookup for this kind of values πŸ˜›

    Reply
  • Roberto, 2015-04-17, 23:48

    Hi, I have a problem using this library: I have a Stored procedure that return always a result set with a single row, but when i use fetch_assoc() I don’t fount anything.

    I’m using $db->query(“Call mystored();”); and then
    $db->fetch_assoc();

    I’ve also try to see the founded rows but it is always 0.

    I’ve tried the same query on Mysql workbench and then i can see the result set and on the log 1 row returned.

    Thanks in advance

    Reply
    • Stefan Gabos, 2016-01-12, 01:41

      I’ve never used stored procedures, but it looks like you have to make an extra call to the “query” method. See these examples here

  • Edy Galantzan, 2015-12-14, 22:32

    How to fix

    Warning: var_export does not handle circular references in /home/kedesign/system/Zebra_Database-master/Zebra_Database.php on line 3497

    Reply
  • Kuno, 2015-12-23, 18:37

    Major problem with performance
    normal 10 row, 10 different query takes 10 milliseconds from mysql to php, this does at 100 milliseconds
    problems:
    1. connects every time before query
    2. so many cycles and checks

    second problem is to build filter
    cannot to: “WHERE name = ?”, array() – empty array
    u have to build own filter – stupid … why i have to do that my self if library is suposed to easy things.

    Reply

Leave a Reply

Your email address will not be published
You can use <strong>, <em>, <a>, <img>, <code>
Characters are not case-sensitive