I experiment with a new script
but cannot figure why I cannot output data from DB
thank you
<?php
//common_db.inc
$dbhost = 'aaaaa';
$dbusername = 'bbbbbb';
$dbuserpassword = 'cccccc';
$default_dbname = 'ddddd';
$MYSQL_ERRNO = '';
$MYSQL_ERROR = '';
function db_connect() {
global $dbhost, $dbusername, $dbuserpassword, $default_dbname;
global $MYSQL_ERRNO, $MYSQL_ERROR;
$link_id = mysql_connect($dbhost, $dbusername, $dbuserpassword);
if(!$link_id) {
$MYSQL_ERRNO = 0;
$MYSQL_ERROR = "Connection failed to the host $dbhost.";
return 0;
}
else if(empty($dbname) && !mysql_select_db($default_dbname)) {
$MYSQL_ERRNO = mysql_errno();
$MYSQL_ERROR = mysql_error();
return 0;
}
else return $link_id;
}
function sql_error() {
global $MYSQL_ERRNO, $MYSQL_ERROR;
if(empty($MYSQL_ERROR)) {
$MYSQL_ERRNO = mysql_errno();
$MYSQL_ERROR = mysql_error();
}
return "$MYSQL_ERRNO: $MYSQL_ERROR";
}
$result = mysql_query("select bus_name, first_name, last_name, fax,user_name from bol_ag where fax is not null,'$link_id' "
;
$fp = fopen("./dump.sql", "a"
;
while($row = mysql_fetch_array($result)) {
fwrite($fp, "insert into table ".
"values ('$row[col1]', '$row[col2],'$row[col3],'$row[col4],'$row[col5]')\n"
;
}
fclose($fp);
// Reading the data back in
$arr = file("./dump.sql"
;
for($i=0; $i<sizeof($arr); $i++) {
mysql_query($arr[$i]);
// execute each line as SQL statement
}
$csv_output = "column 1, column 2, column 3, column 4, column 5";
$csv_output .= "\n";
$result = mysql_query("select bus_name, first_name, last_name, fax,user_name from bol_ag where fax is not null, '$link_id' "
;
while($row = mysql_fetch_array($result)) {
$csv_output .= "$row[col1],$row[col2],$row[col3],$row[col4],$row[col5]\n";
}
header("Content-type: application/vnd.ms-excel"
;
header("Content-disposition: csv" . date("Y-m-d"
. ".xls"
;
print $csv_output;
exit;
?>
but cannot figure why I cannot output data from DB
thank you
<?php
//common_db.inc
$dbhost = 'aaaaa';
$dbusername = 'bbbbbb';
$dbuserpassword = 'cccccc';
$default_dbname = 'ddddd';
$MYSQL_ERRNO = '';
$MYSQL_ERROR = '';
function db_connect() {
global $dbhost, $dbusername, $dbuserpassword, $default_dbname;
global $MYSQL_ERRNO, $MYSQL_ERROR;
$link_id = mysql_connect($dbhost, $dbusername, $dbuserpassword);
if(!$link_id) {
$MYSQL_ERRNO = 0;
$MYSQL_ERROR = "Connection failed to the host $dbhost.";
return 0;
}
else if(empty($dbname) && !mysql_select_db($default_dbname)) {
$MYSQL_ERRNO = mysql_errno();
$MYSQL_ERROR = mysql_error();
return 0;
}
else return $link_id;
}
function sql_error() {
global $MYSQL_ERRNO, $MYSQL_ERROR;
if(empty($MYSQL_ERROR)) {
$MYSQL_ERRNO = mysql_errno();
$MYSQL_ERROR = mysql_error();
}
return "$MYSQL_ERRNO: $MYSQL_ERROR";
}
$result = mysql_query("select bus_name, first_name, last_name, fax,user_name from bol_ag where fax is not null,'$link_id' "
$fp = fopen("./dump.sql", "a"
while($row = mysql_fetch_array($result)) {
fwrite($fp, "insert into table ".
"values ('$row[col1]', '$row[col2],'$row[col3],'$row[col4],'$row[col5]')\n"
}
fclose($fp);
// Reading the data back in
$arr = file("./dump.sql"
for($i=0; $i<sizeof($arr); $i++) {
mysql_query($arr[$i]);
// execute each line as SQL statement
}
$csv_output = "column 1, column 2, column 3, column 4, column 5";
$csv_output .= "\n";
$result = mysql_query("select bus_name, first_name, last_name, fax,user_name from bol_ag where fax is not null, '$link_id' "
while($row = mysql_fetch_array($result)) {
$csv_output .= "$row[col1],$row[col2],$row[col3],$row[col4],$row[col5]\n";
}
header("Content-type: application/vnd.ms-excel"
header("Content-disposition: csv" . date("Y-m-d"
print $csv_output;
exit;
?>