0

Unable to get the data base backup

$this->load->dbutil();
$db_format=array('format'=>'zip','filename'=>'my_db_backup.sql');
$backup=& $this->dbutil->backup($db_format);
$dbname='backup-on-'.date('Y-m-d').'.zip';
$save='assets/db_backup/'.$dbname;
write_file($save,$backup);
force_download($dbname,$backup);

I have tried the above mentioned code. It shows the below mentioned error.

Database error occured. Please contact administrator
Unsupported feature of the database platform you are using.

Filename: C:\xampp\htdocs\innowork-v4\api\system\database\drivers\mysqli\mysqli_utility.php

Line Number: 83

Kindly assist me how to fix it

  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Jun 02 '22 at 13:05
  • I want to know how to take a backup form phpmyadmin in codeigniter – Ramachandran Jun 02 '22 at 13:30

1 Answers1

0

Are you using $db['default']['dbdriver'] = 'mysqli'; driver?

If so, you need to change function _backup in system\database\drivers\mysqli\mysqli_utility.php

/**
 * MySQLi Export
 *
 * @access  private
 * @param   array   Preferences
 * @return  mixed
 */
function _backup($params = array())
{
    // Currently unsupported
    //---return $this->db->display_error('db_unsuported_feature');

    if (count($params) == 0)
    {
        return FALSE;
    }

    // Extract the prefs for simplicity
    extract($params);

    // Build the output
    $output = '';
    foreach ((array)$tables as $table)
    {
        // Is the table in the "ignore" list?
        if (in_array($table, (array)$ignore, TRUE))
        {
            continue;
        }

        // Get the table schema
        $query = $this->db->query("SHOW CREATE TABLE `".$this->db->database.'`.`'.$table.'`');

        // No result means the table name was invalid
        if ($query === FALSE)
        {
            continue;
        }

        // Write out the table schema
        $output .= '#'.$newline.'# TABLE STRUCTURE FOR: '.$table.$newline.'#'.$newline.$newline;

        if ($add_drop == TRUE)
        {
            $output .= 'DROP TABLE IF EXISTS '.$table.';'.$newline.$newline;
        }

        $i = 0;
        $result = $query->result_array();
        foreach ($result[0] as $val)
        {
            if ($i++ % 2)
            {
                $output .= $val.';'.$newline.$newline;
            }
        }

        // If inserts are not needed we're done...
        if ($add_insert == FALSE)
        {
            continue;
        }

        // Grab all the data from the current table
        $query = $this->db->query("SELECT * FROM $table");

        if ($query->num_rows() == 0)
        {
            continue;
        }

        // Fetch the field names and determine if the field is an
        // integer type.  We use this info to decide whether to
        // surround the data with quotes or not

        $i = 0;
        $field_str = '';
        $is_int = array();
        while ($field = mysqli_fetch_field($query->result_id))
        {
            // Most versions of MySQL store timestamp as a string
            $is_int[$i] = (in_array(
                                    //strtolower(mysqli_field_type($query->result_id, $i)),
                                    strtolower($field->type),
                                    array('tinyint', 'smallint', 'mediumint', 'int', 'bigint'), //, 'timestamp'),
                                    TRUE)
                                    ) ? TRUE : FALSE;

            // Create a string of field names
            $field_str .= '`'.$field->name.'`, ';
            $i++;
        }

        // Trim off the end comma
        $field_str = preg_replace( "/, $/" , "" , $field_str);


        // Build the insert string
        foreach ($query->result_array() as $row)
        {
            $val_str = '';

            $i = 0;
            foreach ($row as $v)
            {
                // Is the value NULL?
                if ($v === NULL)
                {
                    $val_str .= 'NULL';
                }
                else
                {
                    // Escape the data if it's not an integer
                    if ($is_int[$i] == FALSE)
                    {
                        $val_str .= $this->db->escape($v);
                    }
                    else
                    {
                        $val_str .= $v;
                    }
                }

                // Append a comma
                $val_str .= ', ';
                $i++;
            }

            // Remove the comma at the end of the string
            $val_str = preg_replace( "/, $/" , "" , $val_str);

            // Build the INSERT string
            $output .= 'INSERT INTO '.$table.' ('.$field_str.') VALUES ('.$val_str.');'.$newline;
        }

        $output .= $newline.$newline;
    }

    return $output;

}

List of changes:

Change all mysql_... to mysqli...

and strtolower(mysqli_field_type($query->result_id, $i)), to strtolower($field->type),

michal.jakubeczy
  • 8,221
  • 1
  • 59
  • 63