LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-02-2011, 08:33 AM   #1
Randall Slack
Member
 
Registered: Feb 2005
Location: Rotterdam, The Netherlands
Distribution: Debian - Ubuntu
Posts: 219

Rep: Reputation: 30
PHP "Object of class mysqli could not be converted to string "


Dear all,

hoping to find some more knowledgable people here, i receive the error

Code:
Object of class mysqli could not be converted to string
the problem is on this particulair line:

Code:
$mbdump .= " --result-file='../packages/".$filename."' ".$this->db->db." ".$tables;
for completeness and posterity, this line comes from the script below:

hopefully someone here can get me on the right track,

much obliged.

<
Code:
?php
/**
 * PDNS-Admin
 * Copyright (c) 2006-2011 Roger Libiez http://www.iguanadons.net
 *
 * Based on Quicksilver Forums
 * Copyright (c) 2005-2011 The Quicksilver Forums Development Team
 *  http://code.google.com/p/quicksilverforums/
 * 
 * Based on MercuryBoard
 * Copyright (c) 2001-2005 The Mercury Development Team
 *  http://www.mercuryboard.com/
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 **/

if (!defined('PDNSADMIN') || !defined('PDNS_ADMIN')) {
	header('HTTP/1.0 403 Forbidden');
	die;
}

/**
 * Database backup
 *
 * @author Aaron Smith-Hayes <davionkalhen@gmail.com>
 * @since 1.0.0
 **/
class backup extends admin
{
	/**
	 * Database backup
	 *
	 * @author Aaron Smith-Hayes <davionkalhen@gmail.com>
	 * @since 1.0.0
	 * @return string HTML
	 **/
	function execute()
	{
		if (!isset($this->get['s'])) {
			$this->get['s'] = '';
		}

		switch($this->get['s'])
		{
		case 'create':
			$this->set_title($this->lang->backup_create);
			$this->tree($this->lang->backup_create);

			return $this->create_backup();
			break;

		case 'restore':
			$this->set_title($this->lang->backup_restore);
			$this->tree($this->lang->backup_restore);

			return $this->restore_backup();
			break;
		}
	}

	/**
	 * Generate a backup
	 *
	 * @author Aaron Smith-Hayes <davionkalhen@gmail.com>
	 * @since 1.0.0
	 * @return string HTML
	 **/
	function create_backup()
	{
		if(!isset($this->post['submit'] ) )
			return eval($this->template('ADMIN_BACKUP'));

		srand();
		$mcookie = sha1( crc32( rand() ) );

		$filename = 'backup_'.$this->version.'-'.date('y-m-d-H-i-s').'-'.$mcookie.'.sql';
		$options = '';

		foreach($this->post as $key => $value )
			$$key = $value;
		if(isset($insert))
			$options .= ' -c';
		if(isset($droptable))
			$options .= ' --add-drop-table';

		$tables = implode( ' ', $this->get_db_tables() );

		$mbdump = "mysqldump ".$options." --password=".$this->db->pass." --host=".$this->db->host." --user=".$this->db->user;
		$mbdump .= " --result-file='../packages/".$filename."' ".$this->db->db." ".$tables;

		if( ($fp = popen($mbdump, 'r') ) === false )
			return $this->message($this->lang->backup_create, $this->lang->backup_failed);

		$buf = '';
		while( $c = fgetc($fp) )
			$buf .= $c;
		pclose($fp);
		$this->chmod("../packages/".$filename, 0440);
		return $this->message($this->lang->backup_create, $this->lang->backup_created ." ../packages/".$filename."<br />". $this->lang->backup_output .": ".$buf, $filename, "../packages/".$filename);
	}

	/**
	 * Restore a backup
	 *
	 * @author Aaron Smith-Hayes <davionkalhen@gmail.com>
	 * @since 1.0.0
	 * @return string HTML
	 **/
	function restore_backup()
	{
		if (!isset($this->get['restore']))
		{
			if ( ($dir = opendir('../packages') ) === false )
				return $this->message($this->lang->backup_restore, $this->lang->backup_no_packages);

			$backups = array();
			while( ($file = readdir($dir) ) )
			{
				if(strtolower(substr($file, -4) ) != '.sql')
					continue;
				$backups[] = $file;
			}
			closedir($dir);

			if(count($backups) <= 0 )
				return $this->message($this->lang->backup_restore, $this->lang->backup_none);

			$output = $this->lang->backup_warning . '<br /><br />';
			$output .= $this->lang->backup_found . ':<br /><br />';
			$count = 0;

			foreach( $backups as $bkup )
			{
				$output .= "<a href='{$this->self}?a=backup&amp;s=restore&amp;restore=".$bkup."'>".$bkup."</a><br />";
			}
			return $this->message($this->lang->backup_restore, $output);
		}

		if(!file_exists('../packages/' . $this->get['restore']) )
			return $this->message($this->lang->backup_restore, $this->lang->backup_noexist);

		$mbimport = "mysql --password=".$this->db->pass." --host=".$this->db->host." --user=".$this->db->user." ".$this->db->name." < ../packages/".$this->get['restore'];
		if( ($fp = popen($mbimport, 'r') ) === false )
			return $this->message($this->lang->backup_restore, $this->lang->backup_import_fail);

		$output = '';
		while($c = fgetc($fp) )
			$output .= $c;
		return $this->message($this->lang->backup_restore, $this->lang->backup_restore_done ."<br />". $this->lang->backup_output .": ".$output);
	}
}
?>

Last edited by Randall Slack; 12-02-2011 at 10:11 AM.
 
Old 12-02-2011, 10:02 AM   #2
Proud
Senior Member
 
Registered: Dec 2002
Location: England
Distribution: Used to use Mandrake/Mandriva
Posts: 2,794

Rep: Reputation: 116Reputation: 116
PHP Code:
        $mbdump "mysqldump ".$options." --password=".$this->db->pass." --host=".$this->db->host." --user=".$this->db->user;
        
$mbdump " --result-file='../packages/".$filename."' ".$this->db->db." ".$tables
Firstly I think the second line here shouldn't be replacing the string we just created on the first line. Did you/someone rewrite this or it really potentially a decade old/presumably well tested?

If you're sure the problem's on this second line, it would seem to be with the type of $this->db->db, because the other uses of $this->db worked, $tables is a string from the implode(), $filename should be one too. I would seek the definition of $this->db->db and what you can do to get a useful string from it in this context.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
"001" and "0012" converted to "01", "12". How? stf92 Programming 7 07-08-2011 06:55 PM
ns:"error when calling class OldSim"&tclsh:"invalid command+child process exits abn." shojaru Linux - Newbie 0 03-05-2009 04:23 AM
Can't locate object method "splitpath" via package "PACK001" at /usr/lib/perl5/5.8.8/ sajigeorge Linux - Software 1 01-11-2009 06:33 AM
which is better "mysql" or "mysqli" to use in php 5.2.6 !? robertjinx Linux - Server 1 12-07-2008 08:32 AM
Can't locate object method "splitpath" via package "File::Spec" RobJohnston Linux - General 2 06-28-2003 09:59 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:10 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration