ADOdb

Database Abstraction Layer for PHP

User Tools

Site Tools


v5:userguide:deprecated

Deprecated Functionality

MySQL and Menus

Connect to MySQL database agora, and generate a <select> menu from an SQL statement where the <option> captions are in the 1st column, and the value to send back to the server is in the 2nd column.

include('adodb.inc.php'); # load code common to ADOdb

$conn = &ADONewConnection('mysql');  # create a connection

$conn->PConnect('localhost','userid','','agora');# connect to MySQL, agora db

$sql = 'select CustomerName, CustomerID from customers';
 
$rs = $conn->Execute($sql);
 
print $rs->GetMenu('GetCust','Mary Rosli');

Here we define a menu named GetCust, with the menu option 'Mary Rosli' selected. See GetMenu(). We also have functions that return the recordset as an array: GetArray(), and as an associative array with the key being the first column: GetAssoc().

Example 9: Exporting in CSV or Tab-Delimited Format

We provide some helper functions to export in comma-separated-value (CSV) and tab-delimited formats:

include_once('/path/to/adodb/toexport.inc.php');
include_once('/path/to/adodb/adodb.inc.php');
 
$db = &NewADOConnection('mysqli');
 
$db->Connect($server, $userid, $password, $database);
 
$rs = $db->Execute('select fname as "First Name", surname as "Surname" from table');
 
print "<pre>";
 
print rs2csv($rs); # return a string, CSV format
print '<hr>';
 
$rs->MoveFirst(); # note, some databases do not support MoveFirst
print rs2tab($rs,false); # return a string, tab-delimited
                         # false == suppress field names in first line
print '<hr>';
 
$rs->MoveFirst();
 
rs2tabout($rs); # send to stdout directly (there is also an rs2csvout function)

print "</pre>";
 
$rs->MoveFirst();
 
$fp = fopen($path, "w");
 
if ($fp) {
 
  rs2csvfile($rs, $fp); # write to file (there is also an rs2tabfile function)

  fclose($fp);
 
}

Carriage-returns or newlines are converted to spaces. Field names are returned in the first line of text. Strings containing the delimiter character are quoted with double-quotes. Double-quotes are double-quoted again. This conforms to Excel import and export guide-lines.

All the above functions take as an optional last parameter, $addtitles which defaults to true. When set to false field names in the first line are suppressed.

v5/userguide/deprecated.txt · Last modified: 2017/04/21 11:50 (external edit)