Link to home
Start Free TrialLog in
Avatar of kwestion
kwestion

asked on

mssql_select_db(): supplied argument is not a valid MS SQL-Link resource

I get the following results from a query I have made.


Warning: mssql_select_db(): supplied argument is not a valid MS SQL-Link resource in C:\Web Services\Apache Group\Apache2\htdocs\itassets\test.php on line 10

Warning: mssql_query(): supplied argument is not a valid MS SQL-Link resource in C:\Web Services\Apache Group\Apache2\htdocs\itassets\test.php on line 13

Fatal error: Call to undefined function mssql_error() in C:\Web Services\Apache Group\Apache2\htdocs\itassets\test.php on line 13

My connection to the DB seems to work fine. Here is the script...

<?php require_once('connection.php'); ?>
<?php
$maxRows_rsUsers = 10;
$pageNum_rsUsers = 0;
if (isset($_GET['pageNum_rsUsers'])) {
  $pageNum_rsUsers = $_GET['pageNum_rsUsers'];
}
$startRow_rsUsers = $pageNum_rsUsers * $maxRows_rsUsers;

mssql_select_db($database_assets, $assets);
$query_rsUsers = "SELECT * FROM asset_assets ORDER BY employee_assets ASC";
$query_limit_rsUsers = sprintf("%s LIMIT %d, %d", $query_rsUsers, $startRow_rsUsers, $maxRows_rsUsers);
$rsUsers = mssql_query($query_limit_rsUsers, $assets) or die(mssql_error());
$row_rsUsers = mssql_fetch_assoc($rsUsers);

if (isset($_GET['totalRows_rsUsers'])) {
  $totalRows_rsUsers = $_GET['totalRows_rsUsers'];
} else {
  $all_rsUsers = mssql_query($query_rsUsers);
  $totalRows_rsUsers = mssql_num_rows($all_rsUsers);
}
$totalPages_rsUsers = ceil($totalRows_rsUsers/$maxRows_rsUsers)-1;
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html><!-- InstanceBegin template="/Templates/template.dwt.php" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<!-- InstanceBeginEditable name="doctitle" -->
<title>Untitled Document</title>
<!-- InstanceEndEditable -->
<!-- InstanceBeginEditable name="head" -->
<!-- InstanceEndEditable -->


<link href="stlye.css" rel="stylesheet" type="text/css">
</head>

<body>
<table width="100%" height="95"  border="0" class="nugheader">
  <tr class="nugget">
    <th scope="col"><p class="style1"><img src="logo.gif" width="267" height="73"></p>
    </th>
  </tr>
</table>
<table width="100%"  border="0">
  <tr valign="top" class="nugget">
    <th width="20%" height="791" valign="top" scope="row"><table width="100%"  border="0" class="nugget">
      <tr>
        <th scope="row"><a href="users.php">User List</a></th>
      </tr>
      <tr>
        <th scope="row"><a href="insert.php">User Entry</a></th>
      </tr>
    </table>
    <table width="100%"  border="0">
      <tr class="nugget">
        <th scope="row">Search</th>
      </tr>
      <tr>
        <th scope="row"><form action="search.php" method="get" name="form1" class="nugget">
          <input type="submit" name="Submit" value="Submit">
          <input name="SearchString" type="text" id="SearchString">
        </form></th>
      </tr>
    </table></th>
    <td width="80%"><!-- InstanceBeginEditable name="Main" -->
      <table width="100%" border="1">
        <tr>
          <td>Employee</td>
          <td>PC Name</td>
          <td>Model</td>
          <td>Manufacturer</td>
          <td>Notes</td>
          <td>Date</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
        </tr>
        <?php do { ?>
        <tr>
          <td><?php echo $row_rsUsers['employee_assets']; ?></td>
          <td><?php echo $row_rsUsers['pcname_assets']; ?></td>
          <td><?php echo $row_rsUsers['model_assets']; ?></td>
          <td><?php echo $row_rsUsers['manufac_assets']; ?></td>
          <td><?php echo $row_rsUsers['notes_assets']; ?></td>
          <td><?php echo $row_rsUsers['date_assets']; ?></td>
          <td><a href="update.php?id_assets=<?php echo $row_rsUsers['id_assets']; ?>">Update</a></td>
          <td><a href="delete.php?id_assets=<?php echo $row_rsUsers['id_assets']; ?>">Delete</a></td>
        </tr>
        <?php } while ($row_rsUsers = mssql_fetch_assoc($rsUsers)); ?>
      </table>
    <!-- InstanceEndEditable --></td>
  </tr>
</table>
</body>
<!-- InstanceEnd --></html>
<?php
mssql_free_result($rsUsers);
?>
Avatar of dr_dedo
dr_dedo
Flag of Egypt image

>>>My connection to the DB seems to work fine.<<<

all the errors you got is because your connection to the db is not working in the first place !!!

there no established connection between ur script and the db

can u post 'connection.php' here ?
Probably $assets is out-of-scope, assuming it is used in connection.php like:

$assets = mssql_connect (HOST, USER, PASS);

Either that or the connect failed for another reason. You can check mysql_error after the connect (if it fails).
>>>Warning: mssql_select_db(): supplied argument is not a valid MS SQL-Link resource in C:\Web Services\Apache Group\Apache2\htdocs\itassets\test.php on line 10

This shows the connection has not been established


Avatar of kwestion
kwestion

ASKER

Hsre is connection.php

<?php
# FileName="Connection_php_mssql.htm"
# Type="MSSQL"
# HTTP="true"
odbc_connect("Assets","sa","password");
?>
I forgot some variables.

<?php
# FileName="Connection_php_mssql.htm"
# Type="MSSQL"
# HTTP="true"
$database_assets = "assets";
$assets = odbc_connect("Assets","sa","Th3Dever");
?>
ASKER CERTIFIED SOLUTION
Avatar of dr_dedo
dr_dedo
Flag of Egypt image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I had been using a DSN, because I cannot seem to connect otherwise.

The username and password are correct, and for the servername, I try the actual name, and localhost. I am using MSSQL Express 2005. Unfortunately, I cannot just use a MySQL DB for this application, or I'd be done by now. :)

Warning: odbc_connect() [function.odbc-connect]: SQL error: [Microsoft][ODBC SQL Server Driver][DBNETLIB]SQL Server does not exist or access denied., SQL state 08001 in SQLConnect in C:\Web Services\Apache Group\Apache2\htdocs\itassets\connection.php on line 10
some tips from here and there
------------------------------------------------------------
The recently released SQL Server 2005 Express will work with MSSQL functions. Here are some caveats:
1) The version of ntwdblib.dll supplied with PHP will not work with Server 2005 (Win32 only). You must use a newer version. The version supplied with SQL Sever 2000 (2000.80.194.0) seems to work well.
2) You must set up mssql_connect to reference the server AND the instance name, eg:
mssql_connect("MyPC\SQLEXPRESS","MyUser","MyPwd");
Although the MSSQL functions work, you might want to consider using the new 'pdo_odbc' (PHP 5.1) with SQL Server 2005 Express for any new code you are writing.
------------------------------------------------------------
Thanks, I beleive that got me connected. Downloaded it from Webzilla.

Now I am left with this.

Warning: mssql_query() [function.mssql-query]: message: Incorrect syntax near 'LIMIT'. (severity 15) in C:\Web Services\Apache Group\Apache2\htdocs\itassets\test.php on line 13

Warning: mssql_query() [function.mssql-query]: Query failed in C:\Web Services\Apache Group\Apache2\htdocs\itassets\test.php on line 13

Fatal error: Call to undefined function mssql_error() in C:\Web Services\Apache Group\Apache2\htdocs\itassets\test.php on line 13




Here is the connection page:
<?php

$server = "SPL-NJ-L395\SQLEXPRESS";

$user = 'sa';
$pass = 'xxxxxx';

$database_assets = "assets";

$assets = mssql_connect( $server, $user, $pass) or trigger_error(mssql_error(),E_USER_ERROR);

?>


And here is line 13:
$rsUsers = mssql_query($query_limit_rsUsers, $assets) or die(mssql_error());

check your SQL syntax, there error is there, try it in msSQL server itself to check its syntax. i don't know if the keyword limit is supported in mssql or not!
It appears I have to play with mssql queries a bit, but its up an running. Thanks.