I'm struggleing with how to get my DSN for an odbc connection that is over a network (i.e. on another drive). The database I'm trying to connect to is an Access database and does not have a username or password required to connect to it. However, I'm not sure what DSN I should be using to connect to it. If anyone can help me with this I would GREATLY appreciate it. I'll post my code below:

//Access connection
$access = odbc_connect('','','');

//MySQL connection
$msql = mysql_connect('localhost','root','');

//Open connection to Access Database
if ($linkID == false){
print "The connection to the Access database failed.";
}else{
print "The connection with the Access database was made successfully.";

//Open connection to MySQL Database
if($linkID == false){
print "The connection to the MySQL database failed.";
}else{
print "The connection with the MySQL database was made successfully.";
}

}
odbc_close($access);
mysql_close($msql);

    For example, when I use the following line of code:

    $access = odbc_connect('G:\Information Services\Shared\PromoDB\PromoDB.mdb','','');
    

    I get the following error message:
    Warning: odbc_connect(): SQL error: [Microsoft][ODBC Driver Manager] Invalid string or buffer length, SQL state S1090 in SQLConnect in fileMaintMaster2.php on line 10

    Also, when I use the mysql_connect() function I get a similar error message:
    Call to undefined function mysql_connect() in fileMaintMaster2.php on line 13

    If anyone can help me with this I would be greatly appreciative. Thanks.

      This is most Likely - a PERMISSIONS problem... PHP is running as the same user as the webserver - and this user MUST HAVE ACCESS TO THE NETWORK SHARE. It most likely does not. Depending upon the version of windows, this can be dificult to achieve.

      Also, The webserver (since it runs as a seperate user) only see's SYSTEM DSN's, not user DSN's.

        Actually the connection to the Access database was made as a System DSN for that specific reason. I believe it could be a DLL problem. I am using the most recent Wamp bundle of php, apache, and mysql. Any other suggestions? Thank you in advanced.

          Once again, and speaking from experience with this, this is most likely a PERMISSIONS problem... The webserver/PHP user does not have access to the network share. Try this:

          1) Disable the apache service
          2) Run apache as the current user from the desktop/prompt
          3) Test your script

          As long as the current user has the network share mapped, it should work...

          What webserver are you running? As a service? Version of Windows?

            I no longer get the error message that I had received previously. Instead I get another error message:

            The connection to the Access database failed.
            PHP Warning: odbc_connect(): SQL error: [MySQL][ODBC 3.51 Driver]Access denied for user 'root'@'localhost' (using password: YES), SQL state S1T00 in SQLConnect in fileMaintMaster2.php on line 10 PHP Notice: Undefined variable: mysql in fileMaintMaster2.php on line 34 PHP Warning: mysql_close(): supplied argument is not a valid MySQL-Link resource in fileMaintMaster2.php on line 34 PHP Warning: odbc_close(): supplied argument is not a valid ODBC-Link resource in fileMaintMaster2.php on line 35

            Again here is my code:

            //Access connection
            					 $access = odbc_connect('PromoDB','root','root'); 
            					           //or die("Connection to the Access database cannot be made.</BR>");
            
            				 //MySQL connection
            				 $msql = @mysql_connect("localhost","root","mysql"); 
            				         //or die("Connection to the MySQL databases cannot be made.</BR>");
            
            				 //Open connection to Access Database
            				 if ($access == false){
              		 		print "The connection to the Access database failed.</BR>";
            				 }else{
              		 		print "The connection with the Access database was made successfully.</BR>";
            						//Open connection to MySQL Database
            						if($mysql == false){
            						  print "The connection to the MySQL database failed.</BR>";
            						}else{
            						  print "The connection with the MySQL database was made successfully.</BR>";
            							if(mysql_select_db("PromoDB", $mysql) == false){
            							   print "The PromoDB database cannot be selected.";
            							}else{
            								 print "The PromoDB was successfully selected.";
            							}								
            						}   
            				 }	 		
              		 mysql_close($mysql);
            				 odbc_close($access);
            

            I am useing the most recent Wamp bundle of Apache(2.0.58), MySQL(???), and PHP(5.1.4). I just noticed that on my Wamp localhost homepage it says:
            "MySQL not launched or bad phpmyadmin config"

            After stopping all services and starting all services again. I continue to get this error message. Thank you very much for you time and help.

              Write a Reply...