Jump to content


Photo

converting from MYSQL to MSSQL/ODBC


  • Please log in to reply
2 replies to this topic

#1 mattock

mattock
  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 29 August 2006 - 09:20 AM

Hi
I'm trying to re-write a simple 'while' loop in php.  I have had to transfer hosts, my old host had MYSQL and i could connect simply by using @mysql_connect.  How ever, my new host is MS SQL and i have to connect using ODBC.

This is my old php code i'm trying to convert to MS SQL/ODBC

$result = @mysql_query ($query);
$row = @mysql_fetch_array ($result, MYSQL_NUM);
if ($result) {
while ($row = mysql_fetch_assoc($result)) {
echo $row['id'];
}
}


I have managed to connect to the database using ODBC ( $result = odbc_exec($conn, $query); ), but i'm not sure what syntax is needed to do the rest!

Thanks in advance

#2 argoSquirrel

argoSquirrel
  • Members
  • PipPipPip
  • Advanced Member
  • 36 posts

Posted 02 September 2006 - 06:54 AM

Have you tried researching mssql server functions?

http://us2.php.net/m...n/ref.mssql.php

#3 matte

matte
  • Members
  • PipPip
  • Member
  • 14 posts

Posted 06 September 2006 - 02:47 PM

try something like this
$db_host = 'localhost';
$db_name= 'dbname';
$db_password = 'dbpass';
$db_username = 'dbuname';

$connection_string = 'DRIVER={SQL Server};SERVER=' . $db_host . ';DATABASE=' . $db_name;
$db_connect = odbc_connect( $connection_string, $db_username, $db_password );
$r1 = odbc_exec($db_connect, "SELECT COL FROM TABLE");
while($q1 = odbc_fetch_array($r1)) {
    echo $q1[COL];
}
odbc_close_all();




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users