[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

MAMP Pro - ODBC - PHP - MySQL

Posted on 2008-01-27
9
Medium Priority
?
3,194 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

0
Comment
Question by:tjstalcup
  • 5
  • 4
9 Comments
 
LVL 10

Expert Comment

by:adrpo
ID: 20756227

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/

0
 

Author Comment

by:tjstalcup
ID: 20756235
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 :(
0
 
LVL 10

Expert Comment

by:adrpo
ID: 20756276

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...
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 

Author Comment

by:tjstalcup
ID: 20756615
It sheds some light, but it still will not allow me to edit the Key - Values
0
 
LVL 10

Expert Comment

by:adrpo
ID: 20756667

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/
0
 
LVL 10

Expert Comment

by:adrpo
ID: 20756714

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/
0
 

Author Comment

by:tjstalcup
ID: 20756789
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
0
 
LVL 10

Accepted Solution

by:
adrpo earned 2000 total points
ID: 20758137

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

0
 

Author Closing Comment

by:tjstalcup
ID: 31425519
Thanks so much.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Backups and Disaster RecoveryIn this post, we’ll look at strategies for backups and disaster recovery.
Article by: Tammy
MySQLTuner is a script written in Perl that allows you to review a MySQL installation quickly and make adjustments to increase performance and stability. The current configuration variables and status data is retrieved and presented in a brief forma…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

611 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question