We help IT Professionals succeed at work.

MAMP Pro - ODBC - PHP - MySQL

Medium Priority
3,470 Views
Last Modified: 2013-11-12
I am starting a training series tomorrow, and the class files were sent to me in different formats, JSP, ASP, PHP, etc.  Well I am using MAMP Pro on my mac, so I of course chose to use PHP.  Well the PHP files contain this odbc_connect("Presidents", , ) line to connect to a DB.  I was told this is DSN???  I noticed that there is a program called ODBC Administrator which is for setting up DSN's, this software comes with my Mac.  I have setup all of the DB's correctly in MySQL, so that is good to go.  And I even downloaded the mysql ODBC driver, which now shows up in ODBC, but I still can't figure out what to do from here.

This is a MAJOR rush!  

Another point, should I just go in and change all of the connection files to just connect to MySQL normally, the way I normally do in PHP?

$connect = odbc_connect("Presidents","","");
		
	$sql = "SELECT FirstName, LastName, StartYear, EndYear, ImagePath 
			FROM Presidents WHERE PresidentID=" . $_GET["Slide"];
	
	$rs = odbc_exec($connect, $sql);
	
	if ( $row = odbc_fetch_row($rs) )
	{
		$firstName = odbc_result($rs, 1);
		$lastName = odbc_result($rs, 2);
		$startYear = odbc_result($rs, 3);
		$endYear = odbc_result($rs, 4);
		$imagePath = odbc_result($rs, 5);
		echo "<President>
			<Name>$firstName $lastName</Name>
			<Years>$startYear - $endYear</Years>
			<Image>$imagePath</Image>
			</President>";
	}
	odbc_close($connect);
}

Open in new window

Comment
Watch Question

Commented:

To connect to DSN Presidents you need to add it in your ODBC Data Sources.
I don't know how is it on MAC, but in Windows, you just add another DSN, give
the odbc driver (MySQL) give the name of the database, the user, the pass and then
you need to give the name: Presidents.

The odbc_connect will go to the ODBC data sources on the system, look for
DSN: Presidents and connect to it.

Cheers,
za-k/

Author

Commented:
So I suppose what I am in need of is how to do this in OBDC Administrator - the program on the mac.  You can add Keys & Values, but when I do, it just says Key | Value, Apple's site says to dbl-click on them to edit them, but i can't :(

Commented:

Here is a bit of tutorial on how you can set up ODBC to MySQL in Jaguar:
http://www.macdevcenter.com/pub/a/mac/2003/06/20/odbc.html

Maybe it sheds some light...

Author

Commented:
It sheds some light, but it still will not allow me to edit the Key - Values

Commented:

It might be that there is a bug in the MySQL driver which causes
ODBC Administrator to crash when adding System DSNs:
http://bugs.mysql.com/bug.php?id=32057

You might be better off using the driver directly from PHP :)

Cheers,
za-k/

Commented:

Hi again,

Directly on the MySQL site:
http://dev.mysql.com/doc/refman/5.0/en/myodbc-configuration-dsn-macosx.html
Warning
There are known issues with the OS X ODBC Administrator and Connector/ODBC that may prevent you from creating a DSN using this method. In this case you should use the command-line or edit the odbc.ini file directly. Note that existing DSNs or those that you create via the myodbc3i tool can still be checked and edited using ODBC Administrator.

Cheers,
za-k/

Author

Commented:
Yeah, I saw that earlier, the terminal command-line launches the Connector/ODBC which then freezes, so I don't understand that.

And I can't find odbc.ini
Commented:

I don't know what to say here.
My experience with Mac is quite limited, and I don't have access to one to test.
I believe the odbc.ini should be in Library/ODBC/odbc.ini
You might need to create the odbc.ini file by hand if the tools
do not work properly. An example of odbc.ini is below.

Have a look at this page at the end.
It says you need to use putenv to set the paths to odbc.ini, etc.
http://www.iodbc.org/index.php?page=languages/php/php-osx-HOWTO

Cheers,
za-k/


[ODBC Data Sources]
 Presidents = MySQL 
        
 [Presidents]
 Debug = 1
 CommLog = 1
 ReadOnly = no
 Driver = /usr/local/lib/mysqlodb3.so
 Servername = 64.xxx.xxx.xx
 FetchBufferSize = 99
 Username = YOUR_USER 
 Password = YOUR_PASS
 Port = 3306
 Database = YOUR_DATABASE
 
 [Default]
 Driver = /path/to/libiodbc-3.0.5/odbcsdk/lib/oplodbc.so.1

Open in new window

Author

Commented:
Thanks so much.