Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

ODBC Connector to MySQL DB

Posted on 2006-07-03
2
Medium Priority
?
997 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 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

Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

Question has a verified solution.

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

This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
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

618 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