473,396 Members | 1,804 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

mssql_query not returning

HI!

I have been using MySQL in connection with PHP for fun for several
years now, but at work they recently wanted me to develop an
application, that uses MS SQL server 2005.

I managed to overcome several problems and can now connect to server
and to database, but the mssql_query isnt returning anything.

Code I use:
************************************************** **********************
$connection= mssql_connect($server, $username, $password)
or die("Couldn't connect to SQL Server on $server");

//select a database to work with
$DB = mssql_select_db($database, $connection)
or die("Couldn't open database $database");

$result=mssql_query("SELECT * FROM Persons")
or die("Couldn't create a result.");

mssql_close($connection);

$num_user=mssql_num_rows($result);

$i=$num_user;

while ($i 0)
{
$Name=mssql_result($result,$i-1,"Name");
echo "$Name<br>";
$i--;
}
************************************************** **********************

I tried this SQL query from MS SQL Server Management Studio and it
works fine. I get my desired result there. I also tried to supply the
$connection after the SQL statement.

I also tried to remove the "or die("Couldn't create a result.");"
part, which continues the program, but the $result is empty.

What am I doing wrong?

Thanks in advance!
Lado

Sep 11 '07 #1
2 2383
La***********@gmail.com wrote:
HI!

I have been using MySQL in connection with PHP for fun for several
years now, but at work they recently wanted me to develop an
application, that uses MS SQL server 2005.

I managed to overcome several problems and can now connect to server
and to database, but the mssql_query isnt returning anything.

Code I use:
************************************************** **********************
$connection= mssql_connect($server, $username, $password)
or die("Couldn't connect to SQL Server on $server");

//select a database to work with
$DB = mssql_select_db($database, $connection)
or die("Couldn't open database $database");

$result=mssql_query("SELECT * FROM Persons")
or die("Couldn't create a result.");

mssql_close($connection);

$num_user=mssql_num_rows($result);

$i=$num_user;

while ($i 0)
{
$Name=mssql_result($result,$i-1,"Name");
echo "$Name<br>";
$i--;
}
************************************************** **********************

I tried this SQL query from MS SQL Server Management Studio and it
works fine. I get my desired result there. I also tried to supply the
$connection after the SQL statement.

I also tried to remove the "or die("Couldn't create a result.");"
part, which continues the program, but the $result is empty.

What am I doing wrong?

Thanks in advance!
Lado
Hi Lado,

Simply look up what the errorcode was.

So remove the 'or die' part from

$result=mssql_query("SELECT * FROM Persons")
or die("Couldn't create a result.")

, and inspect the error using mssql_get_last_message()

Good luck.

Regards,
Erwin Moller

PS: I had trouble with mssql too, and switched to odbc connection to
mssql, which solved a lot of strange things for me. But maybe I setted
up the whole thing bad in the first place.
Sep 11 '07 #2
On 11 sep., 11:57, Erwin Moller
<Since_humans_read_this_I_am_spammed_too_m...@spam yourself.comwrote:
Lado.Lesko...@gmail.com wrote:
HI!
I have been using MySQL in connection with PHP for fun for several
years now, but at work they recently wanted me to develop an
application, that uses MS SQL server 2005.
I managed to overcome several problems and can now connect to server
and to database, but the mssql_query isnt returning anything.
Code I use:
************************************************** **********************
$connection= mssql_connect($server, $username, $password)
or die("Couldn't connect to SQL Server on $server");
//select a database to work with
$DB = mssql_select_db($database, $connection)
or die("Couldn't open database $database");
$result=mssql_query("SELECT * FROM Persons")
or die("Couldn't create a result.");
mssql_close($connection);
$num_user=mssql_num_rows($result);
$i=$num_user;
while ($i 0)
{
$Name=mssql_result($result,$i-1,"Name");
echo "$Name<br>";
$i--;
}
************************************************** **********************
I tried this SQL query from MS SQL Server Management Studio and it
works fine. I get my desired result there. I also tried to supply the
$connection after the SQL statement.
I also tried to remove the "or die("Couldn't create a result.");"
part, which continues the program, but the $result is empty.
What am I doing wrong?
Thanks in advance!
Lado

Hi Lado,

Simply look up what the errorcode was.

So remove the 'or die' part from

$result=mssql_query("SELECT * FROM Persons")
or die("Couldn't create a result.")

, and inspect the error using mssql_get_last_message()

Good luck.

Regards,
Erwin Moller

PS: I had trouble with mssql too, and switched to odbc connection to
mssql, which solved a lot of strange things for me. But maybe I setted
up the whole thing bad in the first place.- Skrij navedeno besedilo -

- Prikaži navedeno besedilo -
Hi, Erwin,

Thanks for your answer. It helped a lot. Appearantly the permissions
for that username weren't set correctly.

Thanks again!

Regards
Lado

Sep 11 '07 #3

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

Similar topics

9
by: mjm | last post by:
Folks, Stroustrup indicates that returning by value can be faster than returning by reference but gives no details as to the size of the returned object up to which this holds. My question is...
8
by: Derek | last post by:
Some authors advocate returning const objects: const Point operator+(const Point&, const Point&); ^^^^^ Returning a const object prevents some bad code from compiling: Point a, b, c; (a +...
10
by: Fraser Ross | last post by:
I need to know the syntax for writing a reference of an array. I haven't seen it done often. I have a class with a member array and I want a member function to return an reference to it. ...
41
by: Materialised | last post by:
I am writing a simple function to initialise 3 variables to pesudo random numbers. I have a function which is as follows int randomise( int x, int y, intz) { srand((unsigned)time(NULL)); x...
3
by: Gazchurchend | last post by:
Hi Ive been using PHP to query data from SQL Server using MSSQL_QUERY for a while now, but recently noticed a problem. I have a notes field in the database (varchar 6000) for entering text. When...
17
by: I.M. !Knuth | last post by:
Hi. I'm more-or-less a C newbie. I thought I had pointers under control until I started goofing around with this: ...
6
by: EvilOldGit | last post by:
const Thing &operator++(int) { Thing temp = *this; operator++(); return temp; } Is this code robust ? I get a compiler warning about returning a reference to a a local, which I guess is...
2
by: BethH | last post by:
According to php.net, mssql_query is supposed to return true when no rows are returned. I'm actually getting an empty resource identifier instead of true. The table is empty, there are no rows...
23
by: pauldepstein | last post by:
Below is posted from a link for Stanford students in computer science. QUOTE BEGINS HERE Because of the risk of misuse, some experts recommend never returning a reference from a function or...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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,...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.