mssql_query not returning
mssql_query not returning
am 11.09.2007 11:14:19 von Lado.Leskovec
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
";
$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
Re: mssql_query not returning
am 11.09.2007 11:57:36 von Erwin Moller
Lado.Leskovec@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
";
> $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.
Re: mssql_query not returning
am 11.09.2007 12:57:40 von Lado.Leskovec
On 11 sep., 11:57, Erwin Moller
wrote:
> 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=3D mssql_connect($server, $username, $password)
> > or die("Couldn't connect to SQL Server on $server");
>
> > //select a database to work with
> > $DB =3D mssql_select_db($database, $connection)
> > or die("Couldn't open database $database");
>
> > $result=3Dmssql_query("SELECT * FROM Persons")
> > or die("Couldn't create a result.");
>
> > mssql_close($connection);
>
> > $num_user=3Dmssql_num_rows($result);
>
> > $i=3D$num_user;
>
> > while ($i > 0)
> > {
> > $Name=3Dmssql_result($result,$i-1,"Name");
> > echo "$Name
";
> > $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=3Dmssql_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=9Ei 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