Copyrights © 2012 Jatin Kotadiya. All Rights Reserved . Powered by Blogger.

Wednesday, October 31, 2012

MS SQL Server with PHP and Codeigniter

Connection With Sql server to php with example

Remote Connection With Sql server to php with example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<?php
 
$server = '192.168.163.158\SQLEXPRESS';
 
// Connect to MSSQL
$link = mssql_connect($server, 'sa', 'sqluser') or die('Something went wrong while connecting to MSSQL');
 
// Send a select query to MSSQL
$query = mssql_query('SELECT * FROM [php].[dbo].[userlist]');
 
// Check if there were any records
if (!mssql_num_rows($query)) {
    echo 'No records found';
} else {
    // The following is equal to the code below:
    //
    // while ($row = mssql_fetch_row($query)) {
 
    while ($row = mssql_fetch_array($query, MSSQL_NUM)) {
        // ...
        echo "<pre>";
        print_r($row);
        echo "</pre>";
    }
}
 
// Free the query result
// Close the link to MSSQL
mssql_close($link);
?>

And Codeigniter Data Base Configuration File like

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/*
| -------------------------------------------------------------------
| DATABASE CONNECTIVITY SETTINGS
| -------------------------------------------------------------------
| This file will contain the settings needed to access your database.
|
| For complete instructions please consult the 'Database Connection'
| page of the User Guide.
|
| -------------------------------------------------------------------
| EXPLANATION OF VARIABLES
| -------------------------------------------------------------------
|
|   ['hostname'] The hostname of your database server.
|   ['username'] The username used to connect to the database
|   ['password'] The password used to connect to the database
|   ['database'] The name of the database you want to connect to
|   ['dbdriver'] The database type. ie: mysql.  Currently supported:
                 mysql, mysqli, postgre, odbc, mssql, sqlite, oci8
|   ['dbprefix'] You can add an optional prefix, which will be added
|                to the table name when using the  Active Record class
|   ['pconnect'] TRUE/FALSE - Whether to use a persistent connection
|   ['db_debug'] TRUE/FALSE - Whether database errors should be displayed.
|   ['cache_on'] TRUE/FALSE - Enables/disables query caching
|   ['cachedir'] The path to the folder where cache files should be stored
|   ['char_set'] The character set used in communicating with the database
|   ['dbcollat'] The character collation used in communicating with the database
|                NOTE: For MySQL and MySQLi databases, this setting is only used
|                as a backup if your server is running PHP < 5.2.3 or MySQL < 5.0.7
|                (and in table creation queries made with DB Forge).
|                There is an incompatibility in PHP with mysql_real_escape_string() which
|                can make your site vulnerable to SQL injection if you are using a
|                multi-byte character set and are running versions lower than these.
|                Sites using Latin-1 or UTF-8 database character set and collation are unaffected.
|   ['swap_pre'] A default table prefix that should be swapped with the dbprefix
|   ['autoinit'] Whether or not to automatically initialize the database.
|   ['stricton'] TRUE/FALSE - forces 'Strict Mode' connections
|                           - good for ensuring strict SQL while developing
|
| The $active_group variable lets you choose which connection group to
| make active.  By default there is only one group (the 'default' group).
|
| The $active_record variables lets you determine whether or not to load
| the active record class
*/
 
$active_group = 'default';
$active_record = TRUE;
 
$db['default']['hostname'] = '192.168.163.158\SQLEXPRESS';
$db['default']['username'] = 'sa';
$db['default']['password'] = 'sqluser';
$db['default']['database'] = 'shop';
$db['default']['dbdriver'] = 'mssql';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;
 
/* End of file database.php */
/* Location: ./application/config/database.php */

YOUR KNOWLEDGE

  • Php & Mssql Pagination Query
    Table :vSalesPerson RowNumber FirstName    LastName               SalesYTD --- -----------  ---------------------- ----------------- 1   Linda        Mitchell               4251368.54 2   Jae          Pak                    4116871.22 3   Michael      Blythe                 3763178.17 4   Jillian      Carson                 3189418.36 5   Ranjit       Varkey Chudukatil      3121616.32 6   José         Saraiva                2604540.71 7   Shu          Ito                    2458535.61 8   Tsvi         Reiter                 2315185.61 9   Rachel       Valdez                 1827066.71 10  Tete         Mensa-Annan            1576562.19 11  David        Campbell               1573012.93 12  Garrett      Vargas                 1453719.46 13  Lynn         Tsoflias               1421810.92 14  Pamela       Ansman-Wolfe           1352577.13 WITH OrderedOrders AS ( ROW_NUMBER() OVER(ORDER BY FirstName DESC) AS RowNumber, FirstName, LastName, ROUND(SalesYTD,2,1) ..

12 comments:

  1. I really liked the way you have described and covered each and every important points.Web Designing Company Bangalore | Website Design Bangalore

    ReplyDelete
  2. Am really Impressed..Its the very interesting article..Am got the some information..Thank you for sharing the useful information...
    Website Designing Company Bangalore | Website Design Companies Bangalore

    ReplyDelete
  3. I really like the way you presented it, great info for fetching data from database
    Website Design Company in Bangalore | Web Development Company in Bangalore

    ReplyDelete
  4. I really appreciate information shared above. It’s of great help. If someone want to learn Online (Virtual) instructor lead live training in Microsoft SQL Server, kindly contact us http://www.maxmunus.com/contact
    MaxMunus Offer World Class Virtual Instructor led training on Microsoft SQL Server. We have industry expert trainer. We provide Training Material and Software Support. MaxMunus has successfully conducted 100000+ trainings in India, USA, UK, Australlia, Switzerland, Qatar, Saudi Arabia, Bangladesh, Bahrain and UAE etc.
    For Demo Contact us.
    Nitesh Kumar
    MaxMunus
    E-mail: nitesh@maxmunus.com
    Skype id: nitesh_maxmunus
    Ph:(+91) 8553912023
    http://www.maxmunus.com/



    ReplyDelete
  5. This article gives the light in which we can observe the reality. this is very nice one and gives in-depth information. Thanks for this nice article.
    SEO Experts India
    SEO Agency Bangalore
    cheapest seo packages

    ReplyDelete
  6. Hi,

    Thanks for sharing a very interesting article about MS SQL Server with PHP and Codeigniter. This is very useful information for online blog review readers. Keep it up such a nice posting like this.

    From,
    Maestro Infotech,
    Web Design Company Bangalore

    ReplyDelete
  7. This comment has been removed by the author.

    ReplyDelete
  8. This is very useful information for online blog review readers. Keep it up such a nice posting like this
    Web design company in chennai
    Web development company in chennai
    Mobile app development company in chennai

    ReplyDelete
  9. Hi,
    Thanks for sharing a very interesting article about MS SQL Server with PHP and Codeigniter. This is very useful information for online blog review readers.

    Regards,
    WondersMind,
    Web Design Company Services

    ReplyDelete





  10. Site Galleria is a Web development company in Bangalore . It provides other services such as Mobile App Development Services for consumer-facing and corporate environments. We also provide Ecommerce web development services, Digital Marketing and SEO Services . We have a team of experienced SEO professionals who will understand your business and create a strategy to fulfil your commercial objectives. Site Galleria is also recognized as best Digital Marketing company in Bangalore

    ReplyDelete