title: PHP + SQL - Using SQL Server 'Create To' scripts to create tables through PHP
body: <p>In SQL Server you seem to be able to get the CREATE TABLE script by right clicking a table, 'Script Table As...' and selecting 'Create To'. I've copied the output script and while it does seem to work and create the table when pasted onto the 'New Query' window, it does not work when used in PHP.
  Example code:</p>
  
  <pre><code>$sqlcommand = 
  "CREATE TABLE [dbo].[departments](
      [department_pk_fk] [varchar](25) NOT NULL,
      [des] [varchar](100) NULL,
      CONSTRAINT [PK_departamentos] PRIMARY KEY CLUSTERED
  (
      [department_pk_fk] ASC
  )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, 
      ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
  ) ON [PRIMARY]
  GO
  ";
  $site_api-&gt;execQuery($sqlcommand);
  </code></pre>
  
  <p>Anyone have any useful input about why this would happen?</p>
  
  <p>Edit: <code>execQuery</code> code:</p>
  
  <pre><code>public function execQuery($q,$scalar=FALSE,$returns=FALSE) {  
  //return an assoc array or a scalar
      global $Cfg, $site_api;
  
      $this-&gt;query=$q;
  
  
      try {
        $result_array = array();
          $result = $this-&gt;conn-&gt;query($this-&gt;query);
          if (is_bool($result)===TRUE) {  //if reslt is true or false then there is nothing to do
              return $result;
          } else {
              if (!$scalar) {
                  if ($result-&gt;rowCount()==0)
                      return null;
                  //SQLSRV
                  while($row = $result-&gt;fetchAll(SQLSRV_FETCH_ASSOC)) {
                      $result_array[]=$row;
                  }
                  $result-&gt;closeCursor();
                  if($returns) return $result_array[0];
              } else {
                  $row = $result-&gt;fetchAll(SQLSRV_FETCH_NUMERIC);
                  if($returns) return $row[0];
              }
          }
      }
      catch (Exception $e) {
          print "Error Code &lt;br&gt;".$e-&gt;getCode();
          print "Error Message &lt;br&gt;".$e-&gt;getMessage();
          print "Strack Trace &lt;br&gt;".nl2br($e-&gt;getTraceAsString());
      }
  }`
  </code></pre>