473,978 Members | 2,024 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

PHP, ODBC, SQL Server Select Statement

I am having a problem getting results back from a SELECT statement
using the script below. The field names contain decimals and I am not
sure wether or not this is causing the problem or not?? I am
connecting to a SQL server db using ODBC, first time connecting to SQL
server but have been using ODBC to connect to Access db's for years. I
have entered the field names just as they are in the table and I have
tried replacing the spaces and decimals with underscores but still
recieve the same error. Anyway, my simple script and the error that I
am recieveing is below. Any help would be greatly appreciated..

$connect = odbc_connect('c abngsql', '', '');
if (!$connect)
{
echo "couldn't connect";
exit;
}
$query1 = "SELECT fol no FROM Protocol.folder ";
$result1 = odbc_exec($conn ect, $query1);
while (odbc_fetch_row ($result1)){
$folder = odbc_result($re sult1, 1);
echo "$folder";
}
?>

ERROR: SQL error: [Microsoft][ODBC SQL Server Driver][SQL
Server]Invalid object name 'Protocol.folde r'., SQL state S0002 in
SQLExecDirect

May 9 '07 #1
4 3521
Try $results1->Fields["fieldname"]->Value

May 9 '07 #2
dkirkdrei wrote:
"SELECT fol no FROM Protocol.folder ";
Do you mean that the table is actually *called* "Protocol.folde r"? If so,
then that's a very poor choice of table name, as the dot is the standard
SQL schema operator.

That is, you can set up several schemas in your database, say, schema A
and schema B, and each schema can contain a table called "foobar". To
differentiate between them, the dot is used:

SELECT * FROM A.foobar;
SELECT * FROM B.foobar;

In Microsoft SQL Server, schemas are linked to users. So each user has
their own schema, thereby allowing multiple users to each create tables
with the same name in the same database. The default schema in MS SQL
Server is, IIRC, "dbo".

But anyway, I digress, although this is a poor choice of table naming, it
is possible to refer to tables with special characters in their names by
quoting them. That is, not:

SELECT * FROM Protocol.folder ;

but:

SELECT * FROM "Protocol.folde r";

If you also wanted to include a schema in there, you could use the
following query:

SELECT * FROM dbo."Protocol.f older";

In general, when choosing identifiers in SQL, I recommend using hostname
rules, except using underscores instead of hyphens. That is: start with a
letter; end with an alphanumeric; everything in between can be
alphanumeric or underscore. I'd also recommend using all lowercase and
avoiding tables and column names with SQL keywords like "order" and
"from".

--
Toby A Inkster BSc (Hons) ARCS
http://tobyinkster.co.uk/
Geek of ~ HTML/SQL/Perl/PHP/Python/Apache/Linux
May 10 '07 #3
On May 9, 5:33 pm, dkirkd...@yahoo .com wrote:
I am having a problem getting results back from a SELECT statement
using the script below. The field names contain decimals and I am not
sure wether or not this is causing the problem or not?? I am
connecting to a SQL server db using ODBC, first time connecting to SQL
server but have been using ODBC to connect to Access db's for years. I
have entered the field names just as they are in the table and I have
tried replacing the spaces and decimals with underscores but still
recieve the same error. Anyway, my simple script and the error that I
am recieveing is below. Any help would be greatly appreciated..
You need square brackets around the table name if it contains special
characters.

May 10 '07 #4
Chung Leong wrote:
You need square brackets around the table name if it contains special
characters.
Square brackets are MS Access/SQL Server proprietary syntax. It is better
to use "double quotes" which Microsoft SQL Server supports along with
almost every other SQL database. [Notable exceptions: Microsoft Access,
MySQL (IIRC, version 5 has a setting to enable support for double-quoted
identifiers, but it's off by default)]

Even if you don't plan on porting this code to another platform, this is
not just a question of "code portability" but "brain portability". It's
best to be in the mindset of using standards-compliant SQL whenever it's
both possible and practical. Otherwise, you'll struggle when you're asked
to develop something for a different RDBMS.

(This is one of the many reasons I prefer PostgreSQL over MySQL: MySQL has
some fairly gratuitous deviations from the SQL standard in some fairly
major areas.)

--
Toby A Inkster BSc (Hons) ARCS
http://tobyinkster.co.uk/
Geek of ~ HTML/SQL/Perl/PHP/Python/Apache/Linux
May 10 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
5217
by: Sean Anderson | last post by:
ODBC under System DSN Setup Access Driver give it the DSN (Data Source Name) MSA Click on Select and point to the myfile.mdb (your database file)
3
3926
by: Richard Muller | last post by:
Hi All, I've got the ASP script shown below that complains as follows: Microsoft OLE DB Provider for ODBC Drivers (0x80004005) Data source name not found and no default driver specified /ShowEvents.asp, line 24 Line 24 of the script is the line:
0
5016
by: Fatt Shin | last post by:
Hi, I'm running MySQL 4.0.13, connecting from PowerBuilder 9 using ODCB Connector 3.51. I'm facing a problem where whenever I issue a SELECT COUNT(*) statement from PowerBuilder, I always get SQL syntax error back from MySQL. (Refer to ODBC Trace I captured below). metrohouse af8-b94 ENTER SQLExecDirect HSTMT 014D2360 UCHAR * 0x020A0EA2 "select count ( *) from code
6
6808
by: Andreas Lauffer | last post by:
I changed from Access97 to AccessXP and I have immense performance problems. Details: - Access XP MDB with Jet 4.0 ( no ADP-Project ) - Linked Tables to SQL-Server 2000 over ODBC I used the SQL Profile to watch the T-SQL-Command which Access ( who creates the commands?) creates and noticed:
11
17605
by: DJJ | last post by:
I am using the MySQL ODBC 3.51 driver to link three relatively small MySQL tables to a Microsoft Access 2003 database. I am finding that the data from the MySQL tables takes a hell of a long time to load making any kind linkage with my Access data virtually useless. I have the MySQL driver setup in as a USER DSN. The MySQL data is sitting out on a server and the Access database is running locally. The network connection is very...
5
6207
by: Todd Huish | last post by:
I have noticed something disturbing when retrieving datasets over a relatively slow line (multiple T1). I am looking at about 25 seconds to retrieve 500 rows via a php-odbc link. This same select from the cli is for all intents practicaly instantaneous. After much research I discovered that PHP by default uses a dynamic cursor type which can be quite a bit slower than a forward only cursor. BTW I have been searching forward only/read...
7
2862
by: Arrun S | last post by:
Hi I don't know how to access the ODBC API through C#. The VS.NET provides OLEDB Data Provider but not ODBC E.g., select * from tbl where id= To get the data type (description) of the column 'id', the ODBC provides a function 'SQLDescribeParam()'. But, I don't know how to access this function through C#.Could anyone help me TIA Arrun
2
9400
by: 111mike | last post by:
Hello, Here's my problem. I cannot connect to mysql database using odbc string connections or dns. I keep getting a "cannot connect to mysql server localhost." I'm running windows XP Pro and have installed IIS as my server. I have installed Mysql 5.0 and mysql ODBC driver 3.51.12 in their default locations. Database is up and running okay, as I've been able to create databases and tables and access them via the command prompt and...
0
2716
by: NM | last post by:
Hello, I've got a problem inserting binary objects into the postgres database. I have binary objects (e.g. images or smth else) of any size which I want to insert into the database. Funny is it works for files larger than 8000 Bytes. If a file is less than 1000 Bytes I get the following message: Error message: --invalid input syntax for type oid: "\074\077......";
0
10359
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10176
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11835
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
11427
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10088
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
8466
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7621
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4744
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.