Solved

ODBC Connector to MySQL DB

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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Loading csv or delimited data files to MySQL database is a very common task frequently questioned about and almost every time LOAD DATA INFILE comes to the rescue. Here we will try to understand some of the very common scenarios for loading data …
Foreword In the years since this article was written, numerous hacking attacks have targeted password-protected web sites.  The storage of client passwords has become a subject of much discussion, some of it useful and some of it misguided.  Of cou…
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…
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…

947 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