Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I'm trying to connect a Microsoft Access Database to a PHP file. The PHP file listed below gives the following 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";
}
?>
like image 270
raj Avatar asked Oct 23 '25 15:10

raj


1 Answers

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

like image 92
IcedAnt Avatar answered Oct 26 '25 07:10

IcedAnt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!