Jump to content

Recommended Posts

Ok,

So i am running MySQL and i have created a wep page that queries my db and shows me the results. No problem. But now i have a firend who wants the same but is running MSSQL.

I want too know is their any simple way in MSSQL too recrate the code below so i can perform the same tasks? If so how? Also how would one format it into individual rows?

Any help is much appreciated

[code]
<?

$username="user";
$password="pass";
$database="db";

//Connect too the database
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM archives ORDER BY id ASC";
$result=mysql_query($query);
$num=mysql_numrows($result);

mysql_close();

echo "<b><center>Database Output</center></b><br><br>";

if ($num>5) {
$to=5;
}else{
$to=$num;
}

$i=0;
while ($i < $to) {

$content=mysql_result($result,$i,"content");

echo "<b>$content</b>";

$i++;
}

?>
[/code]

P.S Yes i realise that it's very simple and unformatted. But it serves it's purpose. And is on a closed network so having the user & pass in plain text isn't a problem :)

Also i dont want too setup ODBC or FreeTDS, (webserver accessing the MSSQL db is on a seprate pc running debian and MSSQL is running on a win2k3 box)

Cheers!
Link to comment
https://forums.phpfreaks.com/topic/9032-mssql-queries/
Share on other sites

Keep in mind that you'll have to enable the mssql extension in php.ini.

Changing between the 2 is very simple, however. Just change all the function calls to mssql_query (for example) instead of mysql_query. Also keep in mind that you won't have access to things like LIMIT/mysql_error().
Link to comment
https://forums.phpfreaks.com/topic/9032-mssql-queries/#findComment-34309
Share on other sites

  • 10 months later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.