Skip to content
</> Mücahit TopalA developer's notebook

Blog/PHP & MySQL

Connecting to MSSQL with PHP

Mücahit Topal 1 min read 8,816 views TREN

First, with the function below, we check whether odbc_connect is available. If it is not available, it can be enabled in the php.ini file.

    if(function_exists(odbc_connect)){
        echo "Can connect to Mssql";
    }else{
        echo "Configure PHP for Mssql first";
    }

then let's connect to our database

$ser="xx.xx.xx.xx"; # our IP address for SQL Server
$db="database_name"; #our database
$user="username"; #username
$pass="enter_password"; # password


$conn=odbc_connect("DRIVER=SQL Server;SERVER=".$ser.";UID=".$user.";PWD=".$pass.";
DATABASE=".$db.";
Address=".$ser.",1433","","");
	
	echo  "

Connection: $conn

"; if ($conn <= 0) { echo "

Failed

"; exit; } else { echo "

Successful

"; };

we have made the connection.

Now let's run a simple query


 
row count [uru_stok_kod] [uru_create_user] [uru_create_date] [uru_lastup_date]
"; ?> "; ?> "; ?> "; ?>
odbc_close($connect); // we close our connection

 

,

Share X Facebook LinkedIn WhatsApp

More from this category

Comments 0

No comments yet.

Leave a comment

Comments appear after approval.