Solved

ODBC Connector to MySQL DB

Posted on 2006-07-03
2
994 Views
Last Modified: 2006-11-18
Hello,

I'm currently trying to connect to a database through a PHP script using the ODBC Connector.  My lines of code are as follows:

$dsn =  "DRIVER={MySQL ODBC 3.51 Driver};" .
"CommLinks=tcpip(Host=localhost);" .
"DatabaseName=handheld;" .
"uid=handheld; pwd=handheld";

$conn = odbc_connect($dsn, "handheld", "handheld");

// Insert statement
$stmt = odbc_prepare($conn, "TRUNCATE TABLE tbl_routing;");

// Check for errors in SQL statement
if (!odbc_execute($stmt))
{
   echo "There has been an error!! - CONNECT";
}

However, I keep getting the error:
Warning: odbc_execute(): SQL error: [unixODBC][MySQL][ODBC 3.51 Driver][mysqld-4.1.12]No database selected, SQL state 3D000 in SQLExecute

I am trying this on a CentOS 4.3 install, php 4.3 and the ODBC 3.51 - MySQL connector installed.

Any more information available on request.  By the way, I need an ODBC connection to the DB as MySQL is only being used temporarily, it will eventually run on a seperate ODBC DB.

Thanks
0
Comment
Question by:daint
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 19

Expert Comment

by:Kim Ryan
ID: 17034003
No database selectedThe key error statement is:

I think this
"DatabaseName=handheld;" .
should be changed to
"DatabaseName=handheld" .

In any case there is something wrong with your clause,  "DatabaseName=handheld;" ., so no databse is specified
0
 
LVL 35

Accepted Solution

by:
Raynard7 earned 250 total points
ID: 17035664
I agree - else you could execute the command;
$stmt = odbc_prepare($conn, "TRUNCATE TABLE handheld.tbl_routing;");
which would also work - as it specifically addresses the schema.
0

Featured Post

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

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

Suggested Solutions

As a database administrator, you may need to audit your table(s) to determine whether the data types are optimal for your real-world data needs.  This Article is intended to be a resource for such a task. Preface The other day, I was involved …
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

737 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