Page 1 of 1

simple query

Posted: Thu Apr 01, 2004 5:54 pm
by ol4pr0
I just need a simple query to see if the mssql works in my php

however it returns Resource id #3

Code: Select all

<?
$host = "10.10.10.5:1433";
$usr = "sa";
$pwd = "sa";
$db = "tms";
                                                                                                                             
$connect = @mssql_connect($host, $usr, $pwd)
or die("Couldn't connect to SQL Server on $host");
                                                                                                                             
$select = @mssql_select_db($db, $connect)
or die("Couldn't open database $db");
                                                                                                                             
$query = "SELECT id_mandet01 FROM tms_mandet01"; 
// id_mandet = field tms_mandet = table
$result = mssql_query($query);
                                                                                                                             
echo $result;
 ?>

Posted: Thu Apr 01, 2004 6:01 pm
by ol4pr0
never mind ;-)

Code: Select all

echo "<table>";
foreach(mssql_fetch_array($result) as $key => $value) {
echo "<tr><td>$key</td><td>$value</td></tr>";
}
echo "</table>";

Posted: Thu Apr 01, 2004 6:03 pm
by tim
seems to me its doing its job, but I dont see any loops to make it show all the id sources. foreach/while =]

edit - blah, nevermind. i'm always late, what I get for opening 10 different browser windows at once. :roll:

Posted: Thu Apr 01, 2004 6:17 pm
by ol4pr0
Well i am always open for other solutions

Posted: Thu Apr 01, 2004 6:35 pm
by Steveo31
tim wrote: edit - blah, nevermind. i'm always late, what I get for opening 10 different browser windows at once. :roll:
LOL! I hate that... :roll:

I had that problem, I think it was because there were no variables with the row, like tim said, something like

Code: Select all

<?php

//query stuff...
$row = mysql_fetch_array($result, MYSQL_ASSOC);
echo $row['variable'];

?>

Posted: Thu Apr 01, 2004 6:37 pm
by ol4pr0
I hope you did relize that it is MSSQL not MYSQL lol, Thanks for the variant tho ;-)

Does php have something called store procedures ?

Posted: Thu Apr 01, 2004 6:42 pm
by markl999
Stored procedures are a database feature.
MySQL has them in version 5.0 (see http://www.mysql.com/doc/en/Stored_Procedures.html)
PostgreSQL just has them ;) (see http://www.roguewave.com/support/docs/s ... g/2-8.html)
I believe mssql has them too, but that's as much as i know about them with mssql ;)

Posted: Thu Apr 01, 2004 6:46 pm
by ol4pr0
MSSQL does have them.. but i am kinda running differant programs doing alot of things.. ( java with mssql , and php does all the other stuff lol ) however i need to make something simular that can be used with the php.

So if there is some way to simulate store procedures from within php that would be nice

Posted: Thu Apr 01, 2004 6:48 pm
by markl999
Hmm, not really sure where you're going with this ;)
As stored procedures are just a bunch of commands that are stored on a server, then i suppose the PHP equivilent is functions and/or classes inside included/required files *shrug*

Posted: Thu Apr 01, 2004 7:00 pm
by ol4pr0
found it thanks... what i was kinda looking for ( sorry if i explained it badly )

Code: Select all

$result = mssql_query("StoredProcedureName ...........
Works great ;-)