ADOdb

Database Abstraction Layer for PHP

User Tools

Site Tools


v5:userguide:deprecated

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
v5:userguide:deprecated [2016/03/14 00:37] mnewnhamv5:userguide:deprecated [2018/06/27 16:16] (current) – function names starting with lowercase (#430) dregad
Line 5: Line 5:
  
 <code php> <code php>
- 
 include('adodb.inc.php'); # load code common to ADOdb 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');
 +</code>
  
-$conn = &ADONewConnection('mysql');  # create a connection+Here we define a menu named GetCust, with the menu option 'Mary Rosliselected. 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().
  
-$conn->PConnect('localhost','userid','','agora');# connect to MySQL, agora db+===== Example 9: Exporting in CSV or Tab-Delimited Format =====
  
-$sql = 'select CustomerName, CustomerID from customers';+We provide some helper functions to export in comma-separated-value (CSV) and tab-delimited formats:
  
-$rs = $conn->Execute($sql);+<code php>
  
-print $rs->GetMenu('GetCust','Mary Rosli');+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);
 +}
 </code> </code>
  
-Here we define a menu named GetCust, with the menu option 'Mary Rosli' selectedSee 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().+Carriage-returns or newlines are converted to spaces. Field names are returned in the first line of textStrings containing the delimiter character are quoted with double-quotesDouble-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.1457912273.txt.gz · Last modified: 2017/04/21 11:39 (external edit)