<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>Question Re: PHP, PDO, ODBC, SQL Anywhere 9, and output to problem in Technology Q&amp;A</title>
    <link>https://community.sap.com/t5/technology-q-a/php-pdo-odbc-sql-anywhere-9-and-output-to-problem/qaa-p/13819933#M4850776</link>
    <description>&lt;P&gt;Our setup:&lt;/P&gt;
&lt;P&gt;server in our office with a MySQL database (Computer A)&lt;/P&gt;
&lt;P&gt;remote server in one of our stores that has a Sybase SQL Anywhere database (Computer B)&lt;/P&gt;
&lt;P&gt;Computer A is trying to contact Computer B to extract data from SQL Anywhere and store it in the MySQL database on Computer A.&lt;/P&gt;
&lt;P&gt;Computer A has an ODBC connection to Computer B.&lt;/P&gt;</description>
    <pubDate>Tue, 16 Jul 2013 07:29:59 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2013-07-16T07:29:59Z</dc:date>
    <item>
      <title>PHP, PDO, ODBC, SQL Anywhere 9, and output to problem</title>
      <link>https://community.sap.com/t5/technology-q-a/php-pdo-odbc-sql-anywhere-9-and-output-to-problem/qaq-p/13819929</link>
      <description>&lt;P&gt;As the subject suggests, I'm using PHP to connect to some SQL Anywhere (9.0.2.3586) databases using ODBC. Here is the code:&lt;/P&gt;
&lt;DIV class="codehilite"&gt;&lt;PRE&gt;&lt;SPAN class="cp"&gt;&amp;lt;?php&lt;/SPAN&gt;
&lt;SPAN class="nv"&gt;$dsn&lt;/SPAN&gt; &lt;SPAN class="o"&gt;=&lt;/SPAN&gt; &lt;SPAN class="s1"&gt;'odbc:DSN=myserver;uid=test;pwd=test'&lt;/SPAN&gt;&lt;SPAN class="p"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="nv"&gt;$user&lt;/SPAN&gt; &lt;SPAN class="o"&gt;=&lt;/SPAN&gt; &lt;SPAN class="s1"&gt;'test'&lt;/SPAN&gt;&lt;SPAN class="p"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="nv"&gt;$pwd&lt;/SPAN&gt; &lt;SPAN class="o"&gt;=&lt;/SPAN&gt; &lt;SPAN class="s1"&gt;'test'&lt;/SPAN&gt;&lt;SPAN class="p"&gt;;&lt;/SPAN&gt;

&lt;SPAN class="nv"&gt;$dbh&lt;/SPAN&gt; &lt;SPAN class="o"&gt;=&lt;/SPAN&gt; &lt;SPAN class="k"&gt;new&lt;/SPAN&gt; &lt;SPAN class="nx"&gt;PDO&lt;/SPAN&gt;&lt;SPAN class="p"&gt;(&lt;/SPAN&gt;&lt;SPAN class="nv"&gt;$dsn&lt;/SPAN&gt;&lt;SPAN class="p"&gt;,&lt;/SPAN&gt; &lt;SPAN class="nv"&gt;$user&lt;/SPAN&gt;&lt;SPAN class="p"&gt;,&lt;/SPAN&gt; &lt;SPAN class="nv"&gt;$pwd&lt;/SPAN&gt;&lt;SPAN class="p"&gt;);&lt;/SPAN&gt;

&lt;SPAN class="nv"&gt;$stmt&lt;/SPAN&gt; &lt;SPAN class="o"&gt;=&lt;/SPAN&gt; &lt;SPAN class="nv"&gt;$dbh&lt;/SPAN&gt;&lt;SPAN class="o"&gt;-&amp;gt;&lt;/SPAN&gt;&lt;SPAN class="na"&gt;prepare&lt;/SPAN&gt;&lt;SPAN class="p"&gt;(&lt;/SPAN&gt;&lt;SPAN class="nv"&gt;$sql&lt;/SPAN&gt;&lt;SPAN class="p"&gt;);&lt;/SPAN&gt;
&lt;SPAN class="cp"&gt;?&amp;gt;&lt;/SPAN&gt;&lt;SPAN class="x"&gt;&lt;/SPAN&gt;
&lt;/PRE&gt;&lt;/DIV&gt;


&lt;P&gt;The SQL statement is really long, so let's say it's something like this:&lt;/P&gt;
&lt;DIV class="codehilite"&gt;&lt;PRE&gt;&lt;SPAN class="nb"&gt;select&lt;/SPAN&gt;
&lt;SPAN class="n"&gt;col1&lt;/SPAN&gt;&lt;SPAN class="p"&gt;,&lt;/SPAN&gt;
&lt;SPAN class="n"&gt;col2&lt;/SPAN&gt;
&lt;SPAN class="n"&gt;from&lt;/SPAN&gt;
&lt;SPAN class="n"&gt;mytable&lt;/SPAN&gt;&lt;SPAN class="p"&gt;;&lt;/SPAN&gt;

&lt;SPAN class="n"&gt;output&lt;/SPAN&gt; &lt;SPAN class="n"&gt;to&lt;/SPAN&gt; &lt;SPAN class="s"&gt;'d:/out/myfile.csv'&lt;/SPAN&gt;
&lt;SPAN class="nb"&gt;format&lt;/SPAN&gt; &lt;SPAN class="n"&gt;ascii&lt;/SPAN&gt;
&lt;SPAN class="n"&gt;quote&lt;/SPAN&gt; &lt;SPAN class="s"&gt;''&lt;/SPAN&gt;
&lt;SPAN class="n"&gt;delimited&lt;/SPAN&gt; &lt;SPAN class="n"&gt;by&lt;/SPAN&gt; &lt;SPAN class="s"&gt;','&lt;/SPAN&gt;
&lt;SPAN class="n"&gt;encoding&lt;/SPAN&gt; &lt;SPAN class="s"&gt;'utf8'&lt;/SPAN&gt;&lt;SPAN class="p"&gt;;&lt;/SPAN&gt;
&lt;/PRE&gt;&lt;/DIV&gt;


&lt;P&gt;I get this error:
    Error: SQLSTATE[42000]: Syntax error or access violation: 0 [Sybase][ODBC Driver][SQL Anywhere]Syntax error near 'OUTPUT' on line 7 (SQLPrepare[0] at extpdo_odbcodbc_driver.c:206)&lt;/P&gt;
&lt;P&gt;To get file output to work with MySQL, I had to add this attribute:&lt;/P&gt;
&lt;P&gt;$attributes = array(PDO::MYSQL_ATTR_LOCAL_INFILE =&amp;gt; true);&lt;/P&gt;
&lt;DIV class="codehilite"&gt;&lt;PRE&gt; &lt;SPAN class="nv"&gt;$dbh&lt;/SPAN&gt; &lt;SPAN class="o"&gt;=&lt;/SPAN&gt; &lt;SPAN class="k"&gt;new&lt;/SPAN&gt; &lt;SPAN class="n"&gt;PDO&lt;/SPAN&gt;&lt;SPAN class="p"&gt;(&lt;/SPAN&gt;&lt;SPAN class="nv"&gt;$dsn&lt;/SPAN&gt;&lt;SPAN class="p"&gt;,&lt;/SPAN&gt; &lt;SPAN class="nv"&gt;$user&lt;/SPAN&gt;&lt;SPAN class="p"&gt;,&lt;/SPAN&gt; &lt;SPAN class="nv"&gt;$pwd&lt;/SPAN&gt;&lt;SPAN class="p"&gt;,&lt;/SPAN&gt; &lt;SPAN class="nv"&gt;$attributes&lt;/SPAN&gt;&lt;SPAN class="p"&gt;);&lt;/SPAN&gt;
&lt;/PRE&gt;&lt;/DIV&gt;


&lt;P&gt;Do I need to do something like that for SQL Anywhere? &lt;/P&gt;
&lt;P&gt;Thanks!!&lt;/P&gt;</description>
      <pubDate>Fri, 12 Jul 2013 10:07:32 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/php-pdo-odbc-sql-anywhere-9-and-output-to-problem/qaq-p/13819929</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2013-07-12T10:07:32Z</dc:date>
    </item>
    <item>
      <title>Re: PHP, PDO, ODBC, SQL Anywhere 9, and output to problem</title>
      <link>https://community.sap.com/t5/technology-q-a/php-pdo-odbc-sql-anywhere-9-and-output-to-problem/qaa-p/13819930#M4850773</link>
      <description>&lt;P&gt;Hi OUTPUT TO is a facility of ISQLs (the client) not of the database engine.&lt;/P&gt;
&lt;P&gt;If you want the engine to do the work then try:&lt;/P&gt;
&lt;DIV class="codehilite"&gt;&lt;PRE&gt;&lt;SPAN class="n"&gt;UNLOAD&lt;/SPAN&gt; 
 &lt;SPAN class="k"&gt;select&lt;/SPAN&gt; &lt;SPAN class="n"&gt;col1&lt;/SPAN&gt;&lt;SPAN class="p"&gt;,&lt;/SPAN&gt; &lt;SPAN class="n"&gt;col2&lt;/SPAN&gt; &lt;SPAN class="k"&gt;from&lt;/SPAN&gt; &lt;SPAN class="n"&gt;mytable&lt;/SPAN&gt;
&lt;SPAN class="k"&gt;INTO&lt;/SPAN&gt; &lt;SPAN class="n"&gt;CLIENT&lt;/SPAN&gt; &lt;SPAN class="n"&gt;FILE&lt;/SPAN&gt;
 &lt;SPAN class="s1"&gt;'d://out//myfile.csv'&lt;/SPAN&gt;
&lt;SPAN class="k"&gt;ENCODING&lt;/SPAN&gt; &lt;SPAN class="s1"&gt;'UTF-8'&lt;/SPAN&gt;
&lt;SPAN class="n"&gt;DELIMITED&lt;/SPAN&gt; &lt;SPAN class="k"&gt;BY&lt;/SPAN&gt; &lt;SPAN class="s1"&gt;','&lt;/SPAN&gt;
&lt;SPAN class="n"&gt;QUOTE&lt;/SPAN&gt; &lt;SPAN class="s1"&gt;''&lt;/SPAN&gt;&lt;SPAN class="p"&gt;;&lt;/SPAN&gt;
&lt;/PRE&gt;&lt;/DIV&gt;


&lt;P&gt;To do a client side unload there are some permission issues, see &lt;A href="http://dcx.sybase.com/index.html#1201/en/dbreference/unload-statement.html"&gt;UNLOAD syntax&lt;/A&gt; for details. Note the escaping of the slashes. (assumes v12.0.1)&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;UPDATE&lt;/STRONG&gt; - However I've just checked v9 (which is many years EOLed now) - it doesn't allow client side unloads, so the unload location would have to be relative to the server. Also there is no support for specifying the encoding. - the syntax would be:&lt;/P&gt;
&lt;DIV class="codehilite"&gt;&lt;PRE&gt;&lt;SPAN class="n"&gt;UNLOAD&lt;/SPAN&gt; 
 &lt;SPAN class="k"&gt;select&lt;/SPAN&gt; &lt;SPAN class="n"&gt;col1&lt;/SPAN&gt;&lt;SPAN class="p"&gt;,&lt;/SPAN&gt; &lt;SPAN class="n"&gt;col2&lt;/SPAN&gt; &lt;SPAN class="k"&gt;from&lt;/SPAN&gt; &lt;SPAN class="n"&gt;mytable&lt;/SPAN&gt;
&lt;SPAN class="k"&gt;INTO&lt;/SPAN&gt; 
 &lt;SPAN class="s1"&gt;'f://out//myfile.csv'&lt;/SPAN&gt;
&lt;SPAN class="n"&gt;DELIMITED&lt;/SPAN&gt; &lt;SPAN class="k"&gt;BY&lt;/SPAN&gt; &lt;SPAN class="s1"&gt;','&lt;/SPAN&gt;
&lt;SPAN class="n"&gt;QUOTES&lt;/SPAN&gt; &lt;SPAN class="k"&gt;OFF&lt;/SPAN&gt;&lt;SPAN class="p"&gt;;&lt;/SPAN&gt;
&lt;/PRE&gt;&lt;/DIV&gt;


&lt;P&gt;where f: is a drive visible to the SERVER. &lt;/P&gt;</description>
      <pubDate>Fri, 12 Jul 2013 12:03:41 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/php-pdo-odbc-sql-anywhere-9-and-output-to-problem/qaa-p/13819930#M4850773</guid>
      <dc:creator>justin_willey</dc:creator>
      <dc:date>2013-07-12T12:03:41Z</dc:date>
    </item>
    <item>
      <title>Re: PHP, PDO, ODBC, SQL Anywhere 9, and output to problem</title>
      <link>https://community.sap.com/t5/technology-q-a/php-pdo-odbc-sql-anywhere-9-and-output-to-problem/qaa-p/13819931#M4850774</link>
      <description>&lt;P&gt;Thanks for your reply. I can use "output to" with dbisql when executed from the command line on the server. It executes the sql on the remote computer and then creates the csv on the server. I was just hoping I could use PHP's built-in PDO functions to run the SQL instead of having to use exec() to run dbisql.&lt;/P&gt;
&lt;P&gt;BTW, I know SQL Anywher v9 is way out-dated, but that's what we're stuck with for now. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 15 Jul 2013 08:27:33 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/php-pdo-odbc-sql-anywhere-9-and-output-to-problem/qaa-p/13819931#M4850774</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2013-07-15T08:27:33Z</dc:date>
    </item>
    <item>
      <title>Re: PHP, PDO, ODBC, SQL Anywhere 9, and output to problem</title>
      <link>https://community.sap.com/t5/technology-q-a/php-pdo-odbc-sql-anywhere-9-and-output-to-problem/qaa-p/13819932#M4850775</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;It executes the sql on the remote computer and then creates the csv on the server.&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;What machine is the SQL Anywhere server running on?&lt;/P&gt;
&lt;P&gt;Using OUTPUT with DBISQL is a perfect choice to export data to clients (where "client" is seen from a SA database server point-of-view).&lt;/P&gt;
&lt;P&gt;However, as Justin has explained, when using your own database client instead of DBISQL, then you will have to use UNLOAD to export data. - If the database server can not access the client directory, you may still use a command shell (or whatever PHP offers here) to move the files to the client-side...&lt;/P&gt;</description>
      <pubDate>Mon, 15 Jul 2013 09:34:09 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/php-pdo-odbc-sql-anywhere-9-and-output-to-problem/qaa-p/13819932#M4850775</guid>
      <dc:creator>VolkerBarth</dc:creator>
      <dc:date>2013-07-15T09:34:09Z</dc:date>
    </item>
    <item>
      <title>Re: PHP, PDO, ODBC, SQL Anywhere 9, and output to problem</title>
      <link>https://community.sap.com/t5/technology-q-a/php-pdo-odbc-sql-anywhere-9-and-output-to-problem/qaa-p/13819933#M4850776</link>
      <description>&lt;P&gt;Our setup:&lt;/P&gt;
&lt;P&gt;server in our office with a MySQL database (Computer A)&lt;/P&gt;
&lt;P&gt;remote server in one of our stores that has a Sybase SQL Anywhere database (Computer B)&lt;/P&gt;
&lt;P&gt;Computer A is trying to contact Computer B to extract data from SQL Anywhere and store it in the MySQL database on Computer A.&lt;/P&gt;
&lt;P&gt;Computer A has an ODBC connection to Computer B.&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jul 2013 07:29:59 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/php-pdo-odbc-sql-anywhere-9-and-output-to-problem/qaa-p/13819933#M4850776</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2013-07-16T07:29:59Z</dc:date>
    </item>
    <item>
      <title>Re: PHP, PDO, ODBC, SQL Anywhere 9, and output to problem</title>
      <link>https://community.sap.com/t5/technology-q-a/php-pdo-odbc-sql-anywhere-9-and-output-to-problem/qaa-p/13819934#M4850777</link>
      <description>&lt;P&gt;Well, if it were the other way around (remote SA database can access the MySQL database), then you might use SA's proxy tables feature (aka "Remote Data Access") to insert/modify data directly from SA tables to MySQL tables - without the need to extract data files. That would require an ODBC connection from B to A - and could be packaged in an SA event or stored procedure to automate that (and protect permissions).&lt;/P&gt;
&lt;P&gt;Apparently, I do not know whether that would be acceptable for you w.r.t. security/responsibility and the like...&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jul 2013 09:01:23 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/php-pdo-odbc-sql-anywhere-9-and-output-to-problem/qaa-p/13819934#M4850777</guid>
      <dc:creator>VolkerBarth</dc:creator>
      <dc:date>2013-07-16T09:01:23Z</dc:date>
    </item>
  </channel>
</rss>

