Jump to content

Recommended Posts

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
Link to comment
https://forums.phpfreaks.com/topic/18989-converting-from-mysql-to-mssqlodbc/
Share on other sites

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();
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.