ODBC Connection to SQL Server and PHP
Posted: Mon Jul 29, 2002 5:17 pm
I created a System ODBC DSN, and I tested the connection through ODBC wizard and it seems fine, but when I try to connect to the database using PHP script, I get the following error:
Couldnt connect to the datasource.
Specified driver could not be loaded due to system error 5 (SQL Server).
I know the sql server account (username and password) has proper permissions, because I connect through JDBC using Java just fine.
I tried multiple functions, none of them works for example this is one of them:
<?php
$connection = odbc_connect('PHPdb','myuser','connectnow') or die ('Couldnt connect to the datasource.<br />'.odbc_errormsg());
// create SQL statement
$sql = "SELECT * FROM phpTest";
$sql_statement = odbc_prepare($connection, $sql) or die ('Couldnt prepare statement.<br />'.odbc_errormsg());
$sql_result = odbc_execute($sql_statement) or die ('Couldnt execute query.<br />'.odbc_errormsg());
odbc_result_all($sql_result, 'border=1') or die(odbc_errormsg());
odbc_free_result($sql_result) or die(odbc_errormsg());
odbc_close($connection);
?>
Any ideas?
Mia
Couldnt connect to the datasource.
Specified driver could not be loaded due to system error 5 (SQL Server).
I know the sql server account (username and password) has proper permissions, because I connect through JDBC using Java just fine.
I tried multiple functions, none of them works for example this is one of them:
<?php
$connection = odbc_connect('PHPdb','myuser','connectnow') or die ('Couldnt connect to the datasource.<br />'.odbc_errormsg());
// create SQL statement
$sql = "SELECT * FROM phpTest";
$sql_statement = odbc_prepare($connection, $sql) or die ('Couldnt prepare statement.<br />'.odbc_errormsg());
$sql_result = odbc_execute($sql_statement) or die ('Couldnt execute query.<br />'.odbc_errormsg());
odbc_result_all($sql_result, 'border=1') or die(odbc_errormsg());
odbc_free_result($sql_result) or die(odbc_errormsg());
odbc_close($connection);
?>
Any ideas?
Mia