PHP MSSQL ADODB Getting the query results

I am a complete newbie to PHP so apologies if this is really basic but all the other things relating to this issue have not worked so far.

I have been having major problems connecting to my GoDaddy MSSQL Server 2005 Database.

Whenever I use the function MSSQL_Connect I get a function does not exist - I contacted GoDaddy technical support as my instinct is there is an issue possibly with the php.ini file (having read other articles on the internet) but they said that I should be connecting via ADODB using the following:

    $conn = new COM("ADODB.Connection") or die("Cannot start ADO");
    $conn->Open("Provider=SQLOLEDB; Data Source='GoDaddyConnectionString';Initial Catalog='GoDaddyDatabase'; User ID='UserID'; Password='Password'");
    $rs = $conn->Execute("Select * from entity");  
    $arr = $rs->GetArray();
    $rs = null;
    $conn = null;
The result that I get on my webpage is

variant Object

Fatal error: Call to undefined method variant::GetArray() in D:\Hosting\9256052\html\telephonenumber.php on line 7
What I am trying to achieve is for the results of the database query to be output into an array for later use.

If someone could help here it would be greatly appreciated.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ray PaseurCommented:
Another "happy" GoDaddy customer!  You are paying them.  They should install the extension for you, test it with an IVV script, and show you an example of how to connect.

I'm guessing you've read all the docs here:

If you want to go forward with ADODB, please change from print_r() to var_dump() and let's see if we can find more of the properties of these objects.
Ray PaseurCommented:
One other possibility... If you're just starting on this project, can you use any other data base?  I can give you plenty of examples of MySQL connections via MySQLi or PDO.
TPLLimitedAuthor Commented:

Thanks for the prompt response.

Sorry I should have mentioned this, its a GoDaddy Windows Server and my main site has been developed with .net which is why it needs to stay MS SQL.

The only reason I am using PHP is due to me being in the process of using Twilio for my phone system and I need this to perform database look ups for customer details.

I have changed print_r() to var_dump() and its come back;

object(variant)#2 (0) { }

Does this mean no records were pulled back? I know there is content in the table as I have just run the same query in the SQL Query builder and 2 rows exist.

Thanks again
10 Tips to Protect Your Business from Ransomware

Did you know that ransomware is the most widespread, destructive malware in the world today? It accounts for 39% of all security breaches, with ransomware gangsters projected to make $11.5B in profits from online extortion by 2019.

Ray PaseurCommented:
I'll try to deconstruct this from var_dump().  Var_dump() explores variables recursively and tell us everything we can know about the variables.

object(variant)#2 (0) { }

This is an object that is an instance of the variant class, the second such instance known to the PHP script.  There are zero properties (member variables) in this object.  Unfortunately, some objects hide their properties inside other objects and behind methods (member functions) and so there may be useful information in this object, but we need some specialized programming to tease it out (last comment below).

You might also want to var_dump($conn), to see what we can find in that thing.

I still believe that GoDaddy should support MSSQL - it's not like that is a fringe case; lots of people use it.

Check these man pages (and all the linked pages) for the big pile of documentation.

These may be helpful.
Dave BaldwinFixer of ProblemsCommented:
The first problem is that Godaddy has not so far installed the Microsoft PHP SQL driver for PHP 5.3 .  The previous extension 'php_mssql' does not work on PHP 5.3+ on Windows on any server anywhere and there is no point in trying to get it to work.

Oops! I was wrong.  I just checked with a new Windows hosting account on Godaddy and it turns out that they have installed the 'sqlsrv' driver for MS SQL.

Here is my demo for 'sqlsrv'.  Put your own info in there and see what you get.
// DB configuration
$dbtable = "yourtable";  // the table we're using
/* Specify the server and connection string attributes. */
$serverName = "YOUR\SQLEXPRESS";    // Your database server
/* Get UID and PWD from application-specific files.  */
$uid = "yourid";      // Your db username
$pwd = "yourpwd";      // Your db password
$connectionInfo = array( "UID"=>$uid,
/* Connect using SQL Server Authentication. */
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn === false )
     echo "Unable to connect.</br>";
     die( print_r( sqlsrv_errors(), true));
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"

<title>sqlsrv demo</title>
<table border="0" cellpadding="0" cellspacing="0" summary="">
<tr valign="top">
<h2 align="center" style="margin: 1px;">sqlsrv demo - PHP/MS-SQL</h2>
<div align="center">MS SQL server 2005 using PHP 'sqlsrv' driver <?php echo $serverName; ?></div>
<table border="0" cellpadding="0" cellspacing="1" summary="local people" width="960px" bgcolor="#336699" style="font-family: Arial; font-size: 11pt;">
if ($conn != "") { 
// Formulate Query
$pgsize = 20;
/* Assign literal parameter values. */
$params = array( 5, 10);
sqlsrv_query( $conn,"SET ROWCOUNT $pgsize");
// --------- Get data from table ---------------
$dquery = "SELECT TOP ($pgsize) ent_num, DisplayName, Sortname, WebSite, Descript, Cat, Approved FROM $dbtable";
$dquery .= " ORDER BY ent_num";
//echo $dquery."<br>";
/* Execute the query. */
if($result = sqlsrv_query( $conn, $dquery, $params, array( "Scrollable" => SQLSRV_CURSOR_KEYSET ))) {
  //echo "Statement executed.\n";
else {
      echo "Error in statement execution.\n";
      die( print_r( sqlsrv_errors(), true));
$nrows = sqlsrv_num_rows($result);

while ($row = sqlsrv_fetch_array($result, SQLSRV_FETCH_NUMERIC)) {
echo '<tr bgcolor="#ffffff">';
echo '<td>&nbsp;'.$row[0].'</td>';
echo '<td>&nbsp;'.$row[1].'</td>';
echo '<td>&nbsp;'.$row[3].'</td>';
echo '<td>&nbsp;'.$row[4].'</td>';
echo '<td>&nbsp;'.$row[5].'</td>';
echo '<td>&nbsp;'.$row[6].'</td>';
echo '</td></tr>';
echo "\r\n";



Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
TPLLimitedAuthor Commented:
sqlsrv did the trick

Many Thanks for your help
Dave BaldwinFixer of ProblemsCommented:
You're welcome, glad to help.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2005

From novice to tech pro — start learning today.