title: CodeIgniter On Azure Connection to Windows Virtual Machine MySql
body: <p>I'm working on a CodeIgniter web project that is being hosted on Azure and i decided to use MySQL on a virtual machine running Windows Server 2012 R2 in Azure following this tutorial as it seemed to be the best solution. <a href="https://azure.microsoft.com/en-gb/documentation/articles/virtual-machines-mysql-windows-server-2008r2/" rel="nofollow">https://azure.microsoft.com/en-gb/documentation/articles/virtual-machines-mysql-windows-server-2008r2/</a></p>
  
  <p>I have it all setup and also managed to connect phpmyadmin hosted in my web project to the Virtual machine so its confirmed that everything works fine.</p>
  
  <p>However, Codeigniter continues to give this error everytime</p>
  
  <pre><code>Unable to connect to your database server using the provided settings.
  
  Filename: D:\home\site\wwwroot\system\database\DB_driver.php
  
  Line Number: 124
  </code></pre>
  
  <p>I decided to create a test php file in the root of my installation with the following code and it connects successfully.</p>
  
  <pre><code>&lt;?php
  // Create connection : Update the hostname , DB username , DB password 
  //, database name. 
  
  $con=mysqli_connect("host","user","password",
  "database");
  
  // Check connection
  if (mysqli_connect_errno()) {
      echo "Failed to connect to MySQL: " . mysqli_connect_errno();
  }
  else
  {
      echo "Connection with MySQL database was successful";
  }
  ?&gt;
  </code></pre>
  
  <p><strong>PLEASE NOTE THAT VALUES HAVE BEEN CHANGED</strong></p>
  
  <p>I went into the system/database/drivers/mysql/mysql_driver.php and removed the "@" symbol to show the exact debugging error for db_pconnect() and i got</p>
  
  <pre><code>A PHP Error was encountered
  
  Severity: Warning
  
  Message: mysql_pconnect(): Access denied for user 'user'@'191.236.147.142' (using password: YES)
  
  Filename: mysql/mysql_driver.php
  
  Line Number: 91
  </code></pre>
  
  <p>But these same details work on a lone php script i mentioned above. Here is my codeIgniter Database config</p>
  
  <pre><code>$active_group = 'default';
  $active_record = TRUE;
  
  $db['default']['hostname'] = 'myvmmysql.cloudapp.net';
  $db['default']['username'] = 'user';
  $db['default']['password'] = 'password';
  $db['default']['database'] = 'database';
  $db['default']['port'] = 3306;
  
  
  $db['default']['dbdriver'] = 'mysql';
  $db['default']['dbprefix'] = '';
  $db['default']['pconnect'] = TRUE;
  $db['default']['db_debug'] = TRUE;
  $db['default']['cache_on'] = FALSE;
  $db['default']['cachedir'] = '';
  $db['default']['char_set'] = 'utf8';
  $db['default']['dbcollat'] = 'utf8_general_ci';
  $db['default']['swap_pre'] = '';
  $db['default']['autoinit'] = TRUE;
  $db['default']['stricton'] = FALSE;
  </code></pre>
  
  <p>Here is a summary of what i have done so far:</p>
  
  <ol>
  <li>I have tried mysql,mysqli and sqlsrv for  $db['default']['dbdriver']</li>
  <li>I have also tried mysql in the test.php file and it still connects to the database</li>
  <li>I have granted public access to the port from all domains in the Virtual Machine</li>
  <li>I have given all privileges grant to the database user from all domains</li>
  <li>The Connection basically works everywhere except in codeigniter.</li>
  <li>I have also tried changing $db['default']['pconnect'] = FALSE; Not
  working
  <strong>NB:</strong> I have already done the necessary things involved in using database with codeigniter... this is more than that</li>
  </ol>
  
  <p>Thank you</p>