July 06, 2008, 11:58:42 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: We are constantly trying to improve phpfreaks and these forums, so feel free to go to the PHPFreaks Comments/Suggestions board and point out anything you'd like to see different!
 
   Home   Help Search Calendar Rules Staff List Login Register  
Pages: [1]
  Print  
Author Topic: [SOLVED] mssql won't give up the info  (Read 90 times)
0 Members and 1 Guest are viewing this topic.
ag3nt42
Member
Offline Offline

Posts: 210


Paradoxx Assassin


View Profile WWW
« on: May 20, 2008, 10:55:31 AM »

I'm having some trouble with this... i'm using php to talk with MSSQL 2005 (not express)
I have been able to create and populate tables however I can't seem to retrieve the information.
Its my understanding that the information needs to be placed into an array so I have done so.. yet no matter what variation i try I cannot get it to retrieve and display the info..

below is the code i'm using:
Code:
<?php
$con 
mssql_connect("localhost","MyUsername","Mypassword");


if (!
$con)
&
#160; {
&#160; die('Could not connect: ' . mssql_error());
&#160; }

mssql_select_db("MyDatabase"$con);

$result mssql_query("SELECT * FROM Account Numbers");

for (
$i 0$i mssql_num_rows$result ); $i++)
&
#160; &#160; {
&#160; &#160; &#160; &#160; $row = mssql_fetch_row($result);
&#160; &#160; }

Echo ("AccountNumbersID: ".$row[0]."<br />");
Echo (
"Account Number: ".$row[1]."<br />");
Echo (
"Description: ".$row[2]."<br />");
Echo (
"Appropriation Balance: ".$row[3]."<br />");
Echo (
"Net Change: ".$row[4]."<br />");
Echo (
"Ending Balance: ".$row[5]."<br />");

echo(
'Cheese');
?>




thanx in advance everyone..

~ag3nt42
« Last Edit: May 20, 2008, 10:56:29 AM by ag3nt42 » Logged

Only those whom are bold enough to chase dreams.. Have the ability to catch them, and beat! them into a merciless submission.

If you feel the need Donate!
MadTechie
PHP Help Guru
**********
Offline Offline

Posts: 5,270


I try to F1


View Profile
« Reply #1 on: May 20, 2008, 11:05:35 AM »

try this

Code:
<?php
$con 
mssql_connect("localhost","MyUsername","Mypassword");


if (!
$con)
{
die(
'Could not connect: ' mssql_error());
}

mssql_select_db("MyDatabase"$con);

$result mssql_query("SELECT * FROM Account Numbers")or die(mssql_error());

while(
$row mssql_fetch_row($result))
{
Echo (
"AccountNumbersID: ".$row[0]."<br />");
Echo (
"Account Number: ".$row[1]."<br />");
Echo (
"Description: ".$row[2]."<br />");
Echo (
"Appropriation Balance: ".$row[3]."<br />");
Echo (
"Net Change: ".$row[4]."<br />");
Echo (
"Ending Balance: ".$row[5]."<br />");
}

echo(
'Cheese');
?>


Logged


--->I don't always test my code posted here<---
Quote
USE[ code ][ /code ]PLEASE
please read the
RULES
Also Remember to Click Solved, how to ask questions - the smart way
ag3nt42
Member
Offline Offline

Posts: 210


Paradoxx Assassin


View Profile WWW
« Reply #2 on: May 20, 2008, 12:15:14 PM »

no its not working either pretty much getting the same problem... only now it throws up a 500 error
Logged

Only those whom are bold enough to chase dreams.. Have the ability to catch them, and beat! them into a merciless submission.

If you feel the need Donate!
MatthewJ
Member
Offline Offline

Posts: 69


View Profile
« Reply #3 on: May 20, 2008, 12:32:28 PM »

The following works for me with sql 2005, you shouldbe able to plug your values and be okay.

Hope it helps

Code:
<?php

    
//Host
    
$SERVER "yourhost";
   
//Account to login with
    
$ADMIN_NAME "yourlogin";
    
//complete pass with your pass
    
$ADMIN_PASS "yourpass";
    
//name of database you want to connect to
    
$DATABASE "yourdatabase";

    
$conn mssql_connect($SERVER$ADMIN_NAME$ADMIN_PASS)
        or die (
"Can't connect to Microsoft SQL Server");
       
    
mssql_select_db($DATABASE$conn)
        or die (
"Can't connect to Database");

$sql "SELECT *
        FROM yourtable"
;

$result mssql_query($sql$conn) or die("Wrong database name");
$row_rsRes mssql_fetch_assoc($result);
             
$totalRows_rsRes mssql_num_rows($result);
echo "<table>";
echo "<tr><td><b>Header1</b></td><td><b>Header2</b></td";
do { ?>

          <tr>
            <td width="15%"><?php echo $row_rsRes['field1']; ?></td>
            <td width="15%"><?php echo $row_rsRes['field2']; ?></td>
          </tr>
          <?php } while ($row_rsRes mssql_fetch_assoc($result)); ?>
 
<?php          
   
echo "</table>";
?>
Logged
ag3nt42
Member
Offline Offline

Posts: 210


Paradoxx Assassin


View Profile WWW
« Reply #4 on: May 21, 2008, 08:25:53 AM »

i tried pluggin my info into this but it keeps coming back with "wrong database name"
even tho i'm 100%positive the database name is correct.. I can use the exact same info to populate the tables or create them but I just can't seem to retrieve anything.

anyone know if any settings that might need to be changed..?

thanx again for the help everyone
« Last Edit: May 21, 2008, 08:27:04 AM by ag3nt42 » Logged

Only those whom are bold enough to chase dreams.. Have the ability to catch them, and beat! them into a merciless submission.

If you feel the need Donate!
MatthewJ
Member
Offline Offline

Posts: 69


View Profile
« Reply #5 on: May 21, 2008, 08:35:41 AM »

Do notice that "Wrong database name" is the error I put in at the mssql_query()... This was specific to the app I was developing.

You may want to change that, it is more likely that the sql query is failing. If not, you would get the "Can't connect to Database" message from mssql_select_db().

do you have the ability to run the sql through SQL Server management studio or something like that to see if the query alone works?
Logged
ag3nt42
Member
Offline Offline

Posts: 210


Paradoxx Assassin


View Profile WWW
« Reply #6 on: May 21, 2008, 08:38:29 AM »

yes i do.. the queries do work if i run them right on the database through the SQL studio.. but they won't retrieve and display the info when I try to rip them out with php

I actually just tested it... for some reason if i place brackets around the data names then it goes as far as to echo out the "HEADER" strings but then i still am not getting ne information displayed
« Last Edit: May 21, 2008, 08:48:40 AM by ag3nt42 » Logged

Only those whom are bold enough to chase dreams.. Have the ability to catch them, and beat! them into a merciless submission.

If you feel the need Donate!
ag3nt42
Member
Offline Offline

Posts: 210


Paradoxx Assassin


View Profile WWW
« Reply #7 on: May 21, 2008, 09:12:29 AM »

wow thanx for all the help everyone i think i got this problem licked...

mathew your code wasn't working for me for somereason but when i went back to the old code i was using and tossed the database names into brackets...

WAHLAH!!! info retrieved... thanx alot for the help guys.
Logged

Only those whom are bold enough to chase dreams.. Have the ability to catch them, and beat! them into a merciless submission.

If you feel the need Donate!
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.5 | SMF © 2006-2008, Simple Machines LLC Valid XHTML 1.0! Valid CSS!