Search
 
SCRIPT & CODE EXAMPLE
 

PHP

connect php in sql server

SQL SERVER 2012 conexion in PHP
<?php
    $serverName = "SERVER"; //serverNameinstanceName
    $connectionInfo = array( "Database"=>"base", "UID"=>"ex", "PWD"=>"******");
    $conn = sqlsrv_connect( $serverName, $connectionInfo);
;

        if( $conn ) {
             echo "Conexión establecida.<br />";
        }else{
            echo "Conexión no se pudo establecer.<br />";
            die( print_r( sqlsrv_errors(), true));
        }

    $sql = "SELECT name FROM [base].[dbo].[table]";
    $params = array();
    $options =  array( "Scrollable" => SQLSRV_CURSOR_KEYSET );
    $stmt = sqlsrv_query( $conn, $sql , $params, $options );

    $row_count = sqlsrv_num_rows( $stmt );
  

        if ($row_count === false)
           echo "Error al obtener datos.";
        else
           echo "bien";
        //echo $row_count;

        while( $row = sqlsrv_fetch_array( $stmt) ) {
              print json_encode($row);
        }

    sqlsrv_close($conn);
?>
Comment

PREVIOUS NEXT
Code Example
Php :: how to remove copyright footer from xenforo 2 
Php :: relationship on the base of condition in laravel 
Php :: laravel route where not contain 
Php :: PHP Example - AJAX Poll 
Php :: dropdown in crud application YII 
Php :: query builder laravel getmedia undefined method 
Php :: php 8 constructor property promotion 
Php :: laravel collection median 
Php :: config in php 
Php :: Replace default WP search and dropdown placeholder 
Php :: learndash logo link 
Php :: php check if weekends 
Php :: php 7.1 functions parameters with "?" 
Php :: laravel collection chunks 
Php :: how to check if coupons are valid or not magento 2 
Php :: How to add page heading in FPDF PHP 
Php :: wordpress production mode wp-config 
Php :: string replace in php 
Php :: eloquentdatatable add column 
Php :: eager load relationships on an existing model in route laravel 
Php :: pass in value in route group middle ware 
Php :: copy(/Users/admin/Library/Caches/composer/files/fakerphp/faker 
Php :: Update database table row if a qualifying token is provided 
Php :: Drupal sync directory in settings.php 
Php :: Laravel retrieving aggregates 
Php :: how to show limited text in laravel on page 
Php :: stripe cb test 
Php :: laravel easy form 
Php :: Laravel 9 Multiple File Upload 
Php :: simplesaml php logout 
ADD CONTENT
Topic
Content
Source link
Name
9+3 =