connecting php and mssql

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kayox007
    New Member
    • Nov 2008
    • 14

    connecting php and mssql

    hi everyone,
    i tried using the code below to connect to my database (MSSQL) but it gave me the error benith. actually am new to php and i dont want to use mysql because am used to MSSQL
    thanks

    code
    Code:
    <?php 
    	$con = mssql_connect('OLUKAYODE\SQLEXPRESS', 'sa', 'admin');
    	mssql_select_db('image', $com);
    	$sql = "select * from main";
    	$get = mssql_query($sql, $com);
    	$data = mssql_fetch_array($get);
    	
    	echo $data["title"];
    	echo $data["file_name"];
    	
    ?>
    error
    Fatal error: Call to undefined function mssql_connect() in C:\wamp\www\gig \crash.php on line 10
    Last edited by Markus; Oct 1 '09, 08:13 PM. Reason: Added [code] tags...
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    You do not have PHP's MSSQL extension enabled. See this link.

    Also, I formatted your post to use [code] tags. In future, please do this yourself.

    Thanks,
    Mark.

    Comment

    • dlite922
      Recognized Expert Top Contributor
      • Dec 2007
      • 1586

      #3
      You need to install the mssql module for php. Did you do that?

      You usually need to uncomment a line in your php.ini

      extension=php_m ssql.dll

      and make sure that dll file exists in your extension directory.



      Dan

      EDIT:

      Dan <-- defeated by Markus's quick replies.

      Comment

      • kayox007
        New Member
        • Nov 2008
        • 14

        #4
        where do i get the MSSQL module for php...

        MarkUs... i followed the link, it told me to copy a ddl file into a folder and i can't find the .dll file.

        thanks

        Comment

        • Markus
          Recognized Expert Expert
          • Jun 2007
          • 6092

          #5
          Originally posted by php.net
          The MSSQL extension is enabled by adding extension=php_m ssql.dll to php.ini.
          Have you done this?

          Comment

          • kayox007
            New Member
            • Nov 2008
            • 14

            #6
            yes just did, but it came up with this error

            Warning: mssql_connect() [function.mssql-connect]: Unable to connect to server: OLUKAYODE\SQLEX PRESS in C:\wamp\www\gig \crash.php on line 10

            Warning: mssql_select_db (): supplied argument is not a valid MS SQL-Link resource in C:\wamp\www\gig \crash.php on line 11

            Warning: mssql_query(): supplied argument is not a valid MS SQL-Link resource in C:\wamp\www\gig \crash.php on line 13

            Warning: mssql_fetch_arr ay(): supplied argument is not a valid MS SQL-result resource in C:\wamp\www\gig \crash.php on line 14

            this is the code

            Code:
            <?php 
            	$con = mssql_connect('OLUKAYODE\SQLEXPRESS', 'sa', 'admin');
            	mssql_select_db('image', $com);
            	$sql = "select * from main";
            	$get = mssql_query($sql, $com);
            	$data = mssql_fetch_array($get);
            	
            	echo $data["title"];
            	echo $data["file_name"];
            	
            ?>

            Comment

            • Markus
              Recognized Expert Expert
              • Jun 2007
              • 6092

              #7
              Please see mssql_get_last_ message() - there is something wrong with your connection information, and the function above should provide you with an error string.

              Code:
              $con = mssql_connect('OLUKAYODE\SQLEXPRESS', 'sa', 'admin');
              
              if (!$con) printf("Connection failed: %s", mssql_get_last_message());

              Comment

              Working...