Php – Warning: odbc_connect(): SQL error: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified

databasems-access-2007PHP

I have connect Ms Access Database to PHP File. PHP file Give Error

"Warning: odbc_connect(): SQL error: [Microsoft][ODBC Driver Manager]

Data source name not found and no default driver specified, SQL state IM002 in SQLConnect in C:\wamp\www\PI\Connection.php on line 3".

Connection.php

<?php
$con = odbc_connect("PIInstitute","","");
if($con){
    echo "Connected";
}else{
    echo "Failed";
}
?>

Best Answer

You need to specify your driver when calling odbc_connect() like so:

$conn =  odbc_connect ( "Driver={SQL Server};Server=$servername;Database=$dbname;", $username, $password ) or die ( "Connection failed: " . $conn );

You can find more info on odbc_connect()here: http://php.net/manual/en/function.odbc-connect.php

Related Topic