Discussion:
Problem with mssql_query()
Chris Boget
2007-05-09 13:57:13 UTC
Permalink
I noticed the following in my logs:

22:04:42 [warning] [D:\PHP\pear\DB\mssql.php][439]: mssql_query(): Unable
to set query
22:04:42 [info] Backtrace: [D:\PHP\pear\DB\mssql.php][439]; function(
mssql_query ); args( 1[value:select @@ERROR as ErrorCode] 2[value:Resource
id #21] )
22:04:42 [info] Backtrace: [D:\PHP\pear\DB\mssql.php][489]; function(
errornative )
22:04:42 [info] Backtrace: [D:\PHP\pear\DB\mssql.php][145]; function(
mssqlraiseerror )
22:04:42 [info] Backtrace: [D:\PHP\pear\DB\common.php][1146]; function(
simplequery ); args( 1[value:SELECT * FROM wording WHERE wording_id =
'8' ] )
22:04:42 [critical] Error in the following query:<br><br>SELECT * FROM
wording WHERE wording_id = '8' <br>DB Error: unknown error
22:04:52 [warning] [D:\PHP\pear\DB\mssql.php][439]: mssql_query(): Unable
to set query
22:04:52 [info] Backtrace: [D:\PHP\pear\DB\mssql.php][439]; function(
mssql_query ); args( 1[value:select @@ERROR as ErrorCode] 2[value:Resource
id #21] )
22:04:52 [info] Backtrace: [D:\PHP\pear\DB\mssql.php][489]; function(
errornative )
22:04:52 [info] Backtrace: [D:\PHP\pear\DB\mssql.php][145]; function(
mssqlraiseerror )
22:04:52 [info] Backtrace: [D:\PHP\pear\DB\common.php][1146]; function(
simplequery ); args( 1[value:SELECT * FROM wording WHERE wording_id =
'8' ] )
22:04:52 [critical] Error in the following query:<br><br>SELECT * FROM
wording WHERE wording_id = '8' <br>DB Error: unknown error

Why is mssql_query() saying that it's unable to set the query? I did some
searching on Google and found that people were having this problem but that
was back in 2001 using an earlier version of PHP. We are using version
4.3.11 and Microsoft SQL Server 2000 - 8.00.2039 (Intel X86).

Has anyone had a similar problem? What was your solution? Why is this
happening?

thnx,
Chris
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Dan Shirah
2007-05-09 15:06:42 UTC
Permalink
Post your block of code from your connection string (Leave out your
username/password info please) to the end of the result set for your query
so I can take a look at it.
Post by Chris Boget
22:04:42 [warning] [D:\PHP\pear\DB\mssql.php][439]: mssql_query(): Unable
to set query
22:04:42 [info] Backtrace: [D:\PHP\pear\DB\mssql.php][439]; function(
id #21] )
22:04:42 [info] Backtrace: [D:\PHP\pear\DB\mssql.php][489]; function(
errornative )
22:04:42 [info] Backtrace: [D:\PHP\pear\DB\mssql.php][145]; function(
mssqlraiseerror )
22:04:42 [info] Backtrace: [D:\PHP\pear\DB\common.php][1146]; function(
simplequery ); args( 1[value:SELECT * FROM wording WHERE wording_id =
'8' ] )
22:04:42 [critical] Error in the following query:<br><br>SELECT * FROM
wording WHERE wording_id = '8' <br>DB Error: unknown error
22:04:52 [warning] [D:\PHP\pear\DB\mssql.php][439]: mssql_query(): Unable
to set query
22:04:52 [info] Backtrace: [D:\PHP\pear\DB\mssql.php][439]; function(
id #21] )
22:04:52 [info] Backtrace: [D:\PHP\pear\DB\mssql.php][489]; function(
errornative )
22:04:52 [info] Backtrace: [D:\PHP\pear\DB\mssql.php][145]; function(
mssqlraiseerror )
22:04:52 [info] Backtrace: [D:\PHP\pear\DB\common.php][1146]; function(
simplequery ); args( 1[value:SELECT * FROM wording WHERE wording_id =
'8' ] )
22:04:52 [critical] Error in the following query:<br><br>SELECT * FROM
wording WHERE wording_id = '8' <br>DB Error: unknown error
Why is mssql_query() saying that it's unable to set the query? I did some
searching on Google and found that people were having this problem but that
was back in 2001 using an earlier version of PHP. We are using version
4.3.11 and Microsoft SQL Server 2000 - 8.00.2039 (Intel X86).
Has anyone had a similar problem? What was your solution? Why is this
happening?
thnx,
Chris
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Chris Boget
2007-05-09 15:20:01 UTC
Permalink
We use PEAR's DB class as our abstration layer. Here is the connection
function from DB\mssql.php:

function connect($dsninfo, $persistent = false)
{
if (!DB::assertExtension('mssql') &&
!DB::assertExtension('sybase')
&& !DB::assertExtension('sybase_ct'))
{
return $this->raiseError(DB_ERROR_EXTENSION_NOT_FOUND);
}
$this->dsn = $dsninfo;
$dbhost = $dsninfo['hostspec'] ? $dsninfo['hostspec'] :
'localhost';
$dbhost .= $dsninfo['port'] ? ',' . $dsninfo['port'] : '';

$connect_function = $persistent ? 'mssql_pconnect' :
'mssql_connect';

if ($dbhost && $dsninfo['username'] && $dsninfo['password']) {
$conn = @$connect_function($dbhost, $dsninfo['username'],
$dsninfo['password']);
} elseif ($dbhost && $dsninfo['username']) {
$conn = @$connect_function($dbhost, $dsninfo['username']);
} else {
$conn = @$connect_function($dbhost);
}
if (!$conn) {
return $this->raiseError(DB_ERROR_CONNECT_FAILED, null,
null,
null,
@mssql_get_last_message());
}
if ($dsninfo['database']) {
if (!@mssql_select_db($dsninfo['database'], $conn)) {
return $this->raiseError(DB_ERROR_NODBSELECTED, null,
null,
null,
@mssql_get_last_message());
}
$this->_db = $dsninfo['database'];
}
$this->connection = $conn;
return DB_OK;
}

We use the DSN: mssql://UID:***@ourhost/db_name. We are not using
persistent connections.

thnx,
Chris


________________________________

From: Dan Shirah [mailto:***@gmail.com]
Sent: Wednesday, May 09, 2007 11:07 AM
To: Chris Boget
Cc: PHP General
Subject: Re: [PHP] Problem with mssql_query()


Post your block of code from your connection string (Leave out your
username/password info please) to the end of the result set for your
query so I can take a look at it.


On 5/9/07, Chris Boget <***@wild.net> wrote:

I noticed the following in my logs:

22:04:42 [warning] [D:\PHP\pear\DB\mssql.php][439]:
mssql_query(): Unable
to set query
22:04:42 [info] Backtrace: [D:\PHP\pear\DB\mssql.php][439];
function(
mssql_query ); args( 1[value:select @@ERROR as ErrorCode]
2[value:Resource
id #21] )
22:04:42 [info] Backtrace: [D:\PHP\pear\DB\mssql.php][489];
function(
errornative )
22:04:42 [info] Backtrace: [D:\PHP\pear\DB\mssql.php][145];
function(
mssqlraiseerror )
22:04:42 [info] Backtrace: [D:\PHP\pear\DB\common.php][1146];
function(
simplequery ); args( 1[value:SELECT * FROM wording WHERE
wording_id =
'8' ] )
22:04:42 [critical] Error in the following query:<br><br>SELECT
* FROM
wording WHERE wording_id = '8' <br>DB Error: unknown error
22:04:52 [warning] [D:\PHP\pear\DB\mssql.php][439]:
mssql_query(): Unable
to set query
22:04:52 [info] Backtrace: [D:\PHP\pear\DB\mssql.php][439];
function(
mssql_query ); args( 1[value:select @@ERROR as ErrorCode]
2[value:Resource
id #21] )
22:04:52 [info] Backtrace: [D:\PHP\pear\DB\mssql.php][489];
function(
errornative )
22:04:52 [info] Backtrace: [D:\PHP\pear\DB\mssql.php][145];
function(
mssqlraiseerror )
22:04:52 [info] Backtrace: [D:\PHP\pear\DB\common.php][1146];
function(
simplequery ); args( 1[value:SELECT * FROM wording WHERE
wording_id =
'8' ] )
22:04:52 [critical] Error in the following query:<br><br>SELECT
* FROM
wording WHERE wording_id = '8' <br>DB Error: unknown error

Why is mssql_query() saying that it's unable to set the query?
I did some
searching on Google and found that people were having this
problem but that
was back in 2001 using an earlier version of PHP. We are using
version
4.3.11 and Microsoft SQL Server 2000 - 8.00.2039 (Intel X86).

Has anyone had a similar problem? What was your solution? Why
is this
happening?

thnx,
Chris

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Richard Lynch
2007-05-09 18:11:03 UTC
Permalink
I dunno 100% for sure about MSsql, but I know for sure that MySQL lets
you do wording_id = '8' when wording_id is an INT and PostgreSQL will
simply throw an error, because '8' is not no way no how an INT. It's
a string.

I suspect MS SQL may be doing the same, in its own unique bland
non-desript way of just saying "error"...

Try losing the '8' and use just 8
Post by Chris Boget
22:04:42 [warning] [D:\PHP\pear\DB\mssql.php][439]: mssql_query(): Unable
to set query
22:04:42 [info] Backtrace: [D:\PHP\pear\DB\mssql.php][439];
function(
2[value:Resource
id #21] )
22:04:42 [info] Backtrace: [D:\PHP\pear\DB\mssql.php][489];
function(
errornative )
22:04:42 [info] Backtrace: [D:\PHP\pear\DB\mssql.php][145];
function(
mssqlraiseerror )
22:04:42 [info] Backtrace: [D:\PHP\pear\DB\common.php][1146]; function(
simplequery ); args( 1[value:SELECT * FROM wording WHERE wording_id =
'8' ] )
22:04:42 [critical] Error in the following query:<br><br>SELECT * FROM
wording WHERE wording_id = '8' <br>DB Error: unknown error
22:04:52 [warning] [D:\PHP\pear\DB\mssql.php][439]: mssql_query(): Unable
to set query
22:04:52 [info] Backtrace: [D:\PHP\pear\DB\mssql.php][439];
function(
2[value:Resource
id #21] )
22:04:52 [info] Backtrace: [D:\PHP\pear\DB\mssql.php][489];
function(
errornative )
22:04:52 [info] Backtrace: [D:\PHP\pear\DB\mssql.php][145];
function(
mssqlraiseerror )
22:04:52 [info] Backtrace: [D:\PHP\pear\DB\common.php][1146]; function(
simplequery ); args( 1[value:SELECT * FROM wording WHERE wording_id =
'8' ] )
22:04:52 [critical] Error in the following query:<br><br>SELECT * FROM
wording WHERE wording_id = '8' <br>DB Error: unknown error
Why is mssql_query() saying that it's unable to set the query? I did some
searching on Google and found that people were having this problem but that
was back in 2001 using an earlier version of PHP. We are using version
4.3.11 and Microsoft SQL Server 2000 - 8.00.2039 (Intel X86).
Has anyone had a similar problem? What was your solution? Why is this
happening?
thnx,
Chris
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Chris
2007-05-10 07:22:55 UTC
Permalink
Post by Richard Lynch
PostgreSQL will
simply throw an error, because '8' is not no way no how an INT. It's
a string.
Since when?

test=# create table b(b int);
CREATE TABLE
test=# insert into b(b) values ('1');
INSERT 0 1
test=# SELECT * from b;
b
---
1
(1 row)

test=# select * from b where b='1';
b
---
1
(1 row)


No idea about the OP's problem but that statement is just wrong :P
--
Postgresql & php tutorials
http://www.designmagick.com/
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Continue reading on narkive:
Loading...