Solved

ODBC Connector to MySQL DB

Posted on 2006-07-03
2
981 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
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

I have been using r1soft Continuous Data Protection (http://www.r1soft.com/linux-cdp/) for many years now with the mySQL Addon and wanted to share a trick I have used several times. For those of us that don't have the luxury of using all transact…
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 …
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

759 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now