DSN-less mySQL connections?

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
Bucholtz
Forum Newbie
Posts: 2
Joined: Mon Nov 04, 2002 2:29 pm

DSN-less mySQL connections?

Post by Bucholtz »

Hi everyone...

I've been working with ASP for a while, and decided that I'd prefer to work with PHP after looking at the code and how much easier it is to work with.

However, I've been looking for a couple days now to see if there was a way to get a DSN-less connection to a database with PHP.

For example, ASP allows the ability to connect to a database that has not been added to the DSN ODBC of the server using the following code :

<%
Set MyConn = Server.CreateObject("ADODB.Connection")
MdbFilePath = Server.MapPath("salesstuff.mdb")
MyConn.Open "Driver={Microsoft Access Driver _
(*.mdb)}; DBQ=" & MdbFilePath & ";"
%>


Is there a way to do something similar in PHP? I ask because I have access to a remote server where I'd like to put a lot of my PHP work, but I don't want to have to pay up the extra cash for them to put my mySQL database in the DSN of the server.

Thanks a lot!
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

by creating a ADODB-COM-Object (Server.CreateObject) your access-db engine is invoked via mdac.
You can create COM-objects in php/win32 with
$var = new COM($progId);

http://www.php.net/manual/en/ref.com.php
Bucholtz
Forum Newbie
Posts: 2
Joined: Mon Nov 04, 2002 2:29 pm

RE:

Post by Bucholtz »

Ok, that answers part of my question, but I still have another issue. The link you posted states:

COM functions are only available on the Windows version of PHP.

Therein lies my problem... the servers in question are Linux servers running mySQL. Is there a way to do this running under a Linux version of PHP? Or would the commands bascally do the same thing?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

afaik you depend on odbc when you want to connect to a access-db with php/linux.
But mySQL does not use DSN-strings to connect to the database.
resource mysql_connect ( [string server [, string username [, string password [, bool new_link [, int client_flags]]]]])
like

Code: Select all

$conn = mysql_connect('www.where.the.server.is', 'dbuser', 'dbpass');
Post Reply