?
Solved

ODBC Connector to MySQL DB

Posted on 2006-07-03
2
Medium Priority
?
1,004 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 500 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

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

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

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
In this article, I’ll talk about multi-threaded slave statistics printed in MySQL error log file.
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…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses
Course of the Month15 days, 14 hours left to enroll

850 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