Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

#5 function mysqlQueryToTable

v1.0 (example)
open
nobody
None
5
2012-02-23
2012-02-23
Anonymous
No

This function is incomplete in the version I downloaded. It did not allow for the database to be passed in the function call. The operational version (at least for me) is below:

/**
* Outputs a MYSQL table or list of tables to an Excel doc
* @param string $host MySQL host to connect to
* @param string $username Username to connect with
* @param string $password Password to connect with
* @param string $db Database to use
* @param mixed $table If string, out specific table. If array, each table will have it's own sheet
*/
public function mysqlQueryToTable($host,$username,$password,$query,$db){
EWXcheckDriverDB('mysql');
if (empty($host)) $this->addError('Database','HOSTNAME is empty');
if (empty($username)) $this->addError('Database','USERNAME is empty');
if (count($this->formatErrors) > 0){return false;}

$link = mysql_connect($host,$username,$password);
if (!$link) $this->addError('Database','UNABLE to connect to '.$host.'('.mysql_error().')');
if (count($this->formatErrors) > 0){return false;}

$db_selected = mysql_select_db($db, $link);

EWXmysqlGenerateByQuery($this,$link,$query);
}
}

Discussion