Kli Posted June 4, 2011 Posted June 4, 2011 I am trying to connect to a MySql database at heliohost using PHP. There was a post "MySql ODBC Driver" from August 2008 (http://www.helionet.org/index/index.php?showtopic=3471&hl=odbc) with a reply from djbob (http://www.helionet.org/index/index.php?showtopic=3471&pid=38289&mode=threaded&start=#entry38289), but it doesn't seem to work now! Here are the connection strings I have tried: $conn = odbc_connect("Driver={MySQL ODBC 3.51 Driver};Server=localhost;Database=myUserName_myDBName;User=myDBUsername;Password=myDBPassword;Option =3;", "myDBUsername", "myDBPassword"); $conn = odbc_connect("DRIVER={MySQL ODBC 3.51 Driver};Server=localhost;Database=myUserName_myDBName;User=myDBUsername;Password=myDBPassword;Option =3;", "myDBUsername", "myDBPassword"); $conn = odbc_connect("Driver={MySQL Driver};Server=localhost;Database=myUserName_myDBName;User=myDBUsername;Password=myDBPassword;Option =3;", "myDBUsername", "myDBPassword"); $conn = odbc_connect("Driver={MySQL ODBC 3.51 Driver};CommLinks=tcpip(Host=localhost);DatabaseName=myUserName_myDBName;uid=myDBUsername;pwd=myDBPa ssword", "myDBUsername", "myDBPassword"); I always get error "odbc_connect() [function.odbc-connect]: SQL error: [unixODBC][Driver Manager]Data source name not found, and no default driver specified, SQL state IM002 in SQLConnect". Has the ODBC driver changed since August 2008? Please Help!
Guest Geoff Posted June 4, 2011 Posted June 4, 2011 Why not just use mysql_connect()? Have you used MySQL before?
Kli Posted June 4, 2011 Author Posted June 4, 2011 Why not just use mysql_connect()? Have you used MySQL before? I'd like to keep my PHP code database-agnostic -- I'm tring to deploy my code in different hosting sites (I do just a SELECT and a few APPENDs in my code) so I thought that odbc_connect() was a good option -- do you have a ODBC connection string that works on a MySql/SqlLite databse on Heliohost? Thanks Edward Clements
Guest Geoff Posted June 4, 2011 Posted June 4, 2011 You're using the wrong solution for this. You should instead look into a database abstraction layer like PDO or Doctrine DBAL. However, I am going to go ahead and escalate this because it looks like you are insistent on using ODBC. @djbob Please see http://www.webaj.com/how-setup-mysql-dsn-d...ommand-line.htm Escalating Request...
Kli Posted June 5, 2011 Author Posted June 5, 2011 Geoff, thanks for escalating the request -- this PHP web-site is simple and straight forward, I just need it to be DB-agnostic (it just does a couple of SELECTs and INSERTs), a database abstraction layer would be overkill... Edward
Kli Posted June 10, 2011 Author Posted June 10, 2011 Which server are you on? I'm on Stevie (http://stevie.heliohost.org). Thanks!
Kli Posted June 12, 2011 Author Posted June 12, 2011 Okay, can you try again now? Sorry, but neither of the four connections in my initial posting work, I still get error odbc_connect() [function.odbc-connect]: SQL error: [unixODBC][Driver Manager]Data source name not found, and no default driver specified, SQL state IM002 in SQLConnect in scriptname.php on line nn mysql_connect() and mysql_select_db() using the same dbname/username/password works ok. Could it be that I have to use a different (variant of) connection string?
Ashoat Posted June 14, 2011 Posted June 14, 2011 Sorry, I should've mentioned that it's version 5.1.8 now. So maybe have the DRIVER as {MySQL ODBC 5.1.8 Driver}?
Kli Posted June 15, 2011 Author Posted June 15, 2011 Sorry, I should've mentioned that it's version 5.1.8 now. So maybe have the DRIVER as {MySQL ODBC 5.1.8 Driver}? All of the following connection strings give the same error "odbc_connect() [function.odbc-connect]: SQL error: [unixODBC][Driver Manager]Data source name not found, and no default driver specified, SQL state IM002 in SQLConnect": $conn = odbc_connect("Driver={MySQL ODBC 5.1.8 Driver};Server=localhost;Database=myUserName_myDBName;User=myDBUsername;Password=myDBPassword;Option =3;", "myDBUsername", "myDBPassword");$conn = odbc_connect("DRIVER={MySQL ODBC 5.1.8 Driver};Server=localhost;Database=myUserName_myDBName;User=myDBUsername;Password=myDBPassword;Option =3;", "myDBUsername", "myDBPassword");$conn = odbc_connect("Driver={MySQL Driver};Server=localhost;Database=myUserName_myDBName;User=myDBUsername;Password=myDBPassword;Option =3;", "myDBUsername", "myDBPassword");$conn = odbc_connect("Driver={MySQL ODBC 5.1.8 Driver};CommLinks=tcpip(Host=localhost);DatabaseName=myUserName_myDBName;uid=myDBUsername;pwd=myDBPa ssword", "myDBUsername", "myDBPassword"); Do I need to change anything else in my connection string(s)?
Ashoat Posted June 15, 2011 Posted June 15, 2011 Honestly, I'm not sure. I can tell you that I installed the MySQL ODBC Connector 5.1.8, but besides that I'm not sure what else needs to be done. Have you tried Googling around for what the valid connection string is? If you have and it isn't working, is there any documentation suggesting that I need to do something more than install ODBC and the MySQL ODBC Connector?
Ashoat Posted June 18, 2011 Posted June 18, 2011 Closing due to inactivity. PM me to reopen! If I'm unresponsive, just open a new support thread and an admin can reopen this thread for you.
Recommended Posts