Commit 0d24be5a authored by smk-ka's avatar smk-ka

by smk-ka: Added MySQLi support (backported from #226135).

parent 07c0ad07
......@@ -6,6 +6,7 @@ Demo x.x-x.x, xxxx-xx-xx
Demo 5.x-1.x, xxxx-xx-xx
------------------------
by smk-ka: Added MySQLi support (backported from #226135).
by smk-ka: Fixed the generation of the table list for multiple database
prefixes.
......
<?php
// $Id$
// Some older mysql client libs are missing this constant.
if (!defined('MYSQLI_BINARY_FLAG')) {
define('MYSQLI_BINARY_FLAG', 128);
}
/**
* Dump active database.
*/
......@@ -73,11 +78,8 @@ function _demo_dump_table_data($table) {
// Dump table data
$result = db_query("SELECT * FROM %s", $table);
if (db_num_rows($result)) {
// Get table fields.
$fields = _demo_get_fields($result);
$num_fields = count($fields);
// Get table fields.
if ($fields = _demo_get_fields($result)) {
// Escape backslashes, PHP code, special chars
$search = array('\\', "'", "\x00", "\x0a", "\x0d", "\x1a");
$replace = array('\\\\', "''", '\0', '\n', '\r', '\Z');
......@@ -98,19 +100,16 @@ function _demo_dump_table_data($table) {
}
// A number
// timestamp is numeric on some MySQL 4.1, BLOBs are sometimes numeric
else if ($fields['meta'][$field]->numeric
&& $fields['meta'][$field]->type != 'timestamp'
&& !($fields['meta'][$field]->blob)) {
else if ($fields[$field]->numeric && !$fields[$field]->timestamp && !$fields[$field]->blob) {
$values[] = $value;
}
// A binary field
// Note: with mysqli, under MySQL 4.1.3, we get the flag
// "binary" for those field types (I don't know why)
else if (stristr($fields['flags'][$field], 'binary')
&& $fields['meta'][$field]->type != 'datetime'
&& $fields['meta'][$field]->type != 'date'
&& $fields['meta'][$field]->type != 'time'
&& $fields['meta'][$field]->type != 'timestamp') {
// A true BLOB
// - mysqldump only generates hex data when the --hex-blob
// option is used, for fields having the binary attribute
// no hex is generated
// - a TEXT field returns type blob but a real blob
// returns also the 'binary' flag
else if ($fields[$field]->binary && $fields[$field]->blob) {
// Empty blobs need to be different, but '0' is also empty :-(
if (empty($value) && $value != '0') {
$values[] = "''";
......@@ -155,11 +154,33 @@ function _demo_dump_table_data($table) {
*/
function _demo_get_fields($result) {
$fields = array();
$num_fields = mysql_num_fields($result);
for ($i = 0; $i < $num_fields; $i++) {
$fields['meta'][] = mysql_fetch_field($result, $i);
$fields['flags'][] = mysql_field_flags($result, $i);
switch ($GLOBALS['db_type']) {
case 'mysql':
$num_fields = mysql_num_fields($result);
for ($i = 0; $i < $num_fields; $i++) {
$meta = mysql_fetch_field($result, $i);
// Enhance field definition with custom properties.
$meta->timestamp = (int)($meta->type == 'timestamp');
$flags = mysql_field_flags($result, $i);
$meta->binary = (int)(stristr($flags, 'binary') !== FALSE);
$fields[] = $meta;
}
break;
case 'mysqli':
while ($meta = mysqli_fetch_field($result)) {
// Enhance the field definition for mysql-extension compatibilty.
$meta->numeric = (int)(bool)($meta->flags & MYSQLI_NUM_FLAG);
$meta->blob = (int)(bool)($meta->flags & MYSQLI_BLOB_FLAG);
// Add custom properties.
$meta->timestamp = (int)($meta->type == MYSQLI_TYPE_TIMESTAMP);
$meta->binary = (int)(bool)($meta->flags & MYSQLI_BINARY_FLAG);
$fields[] = $meta;
}
break;
}
return $fields;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment