[Tutorial] Connect to your DB with PHP

Results 1 to 3 of 3
  1. #1
    Apprentice Mouquette is offline
    MemberRank
    Dec 2010 Join Date
    6Posts

    [Tutorial] Connect to your DB with PHP

    Hello world !

    This tutorial will show you how to connect on your Pangya_S4_TH DB with PHP

    Step
    1 - Configure Server SQL
    2 - Configure PHP
    3 - Connection and SQL query test

    What you need :
    1) Microsoft Server SQL
    2) Pangya_S4_TH installed


    1 - Configure Server SQL

    Execute "SQL Server Configuration Manager" (http://puu.sh/EKML)

    Go to "SQL Server Network Configuration" then on "Protocols for MSSQLSERVER"
    Enable Named Pipes and TCP/IP by right click -> Enable (http://puu.sh/EKRX)

    Right click on TCP/IP => Properties
    Protocol Tab => Listen All => Yes (http://puu.sh/EKT6)
    IP Addresses Tab => IPAll => TCP Port => 1433 (http://puu.sh/EKTm)

    Make sure Named Pipes and TCP/IP are Enabled in "SQL Native Client 10.0 Configuration" => "Client Protocols"
    NB : If you have a 64 bits windows, you will have 2 "SQL Native Client 10.0 Configuration", one for 32 bits, and one for 64 bits

    Go to "SQL Server Services"
    Right click on "SQL Server (MSSQLSERVER)" => Restart (http://puu.sh/EKUL)

    SQL Configuration finished !

    2 - Configure PHP

    Install php_pdo_odbc extension for PHP
    if you have WAMP/EasyPHP, you just have to delete the ";" in front of the line "extension=php_pdo_odbc.dll" in php.ini

    Restart apache

    PHP Configuration finished !

    3 - Connection and SQL query test

    Now it's time to test !

    PHP Code:
    <?php

        $server 
    '127.0.0.1';
        
    $database 'Pangya_S4_TH';
        
    $user 'sa';
        
    $passwd '*****'//Replace ***** by your passwd

        
    $connect odbc_connect("Driver={SQL Server Native Client 10.0};Server=$server;Database=$database;"$user$passwd);

        
    $sql '...'//Replace ... by the SQL query

        
    $result odbc_exec($connect$sql;
        
        while(
    $array odbc_fetch_array($result)) {
            foreach(
    $array as $key => $value) {
                echo 
    $key " : " $value "<br/>";
            }
            echo 
    '<br/><br/>';
        }
        
    ?>
    I did this SQL query to test : SELECT * FROM [Pangya_S4_TH].[dbo].[Pangya_Item_WareHouse] and it work perfectly

    I hope it will help some of you to make a website to manage your Pangya Server ;)


  2. #2
    Deny everything. Tsukasa is offline
    MemberRank
    Jun 2005 Join Date
    Net SlumLocation
    558Posts

    Re: [Tutorial] Connect to your DB with PHP

    Easy to follow, captures all important steps and right to the point. Excellent!

    For all curious minds: Be sure to check out Microsoft's own PHP sqlsrv driver that adds things like unicode support and other cool stuff while you're at it. :)

  3. #3
    LoLonYou chiosin2 is offline
    MemberRank
    Aug 2008 Join Date
    Katipunan_AvenueLocation
    306Posts

    Re: [Tutorial] Connect to your DB with PHP

    had a hard time with my site before but this would make it a lot easier for people trying to make their own tools for the DB.



Advertisement