simple query

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

simple query

Post 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;
 ?>
User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

Post 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>";
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post 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:
User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

Post by ol4pr0 »

Well i am always open for other solutions
Steveo31
Forum Contributor
Posts: 416
Joined: Sun Nov 23, 2003 9:05 pm
Location: San Jose CA

Post 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'];

?>
User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

Post 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 ?
Last edited by ol4pr0 on Thu Apr 01, 2004 6:47 pm, edited 1 time in total.
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post 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 ;)
User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

Post 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
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post 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*
User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

Post 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 ;-)
Post Reply