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\itass ets\test.p hp on line 10
Warning: mssql_query(): supplied argument is not a valid MS SQL-Link resource in C:\Web Services\Apache Group\Apache2\htdocs\itass ets\test.p hp on line 13
Fatal error: Call to undefined function mssql_error() in C:\Web Services\Apache Group\Apache2\htdocs\itass ets\test.p hp on line 13
My connection to the DB seems to work fine. Here is the script...
<?php require_once('connection.p hp'); ?>
<?php
$maxRows_rsUsers = 10;
$pageNum_rsUsers = 0;
if (isset($_GET['pageNum_rsUs ers'])) {
$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_r sUsers, $assets) or die(mssql_error());
$row_rsUsers = mssql_fetch_assoc($rsUsers );
if (isset($_GET['totalRows_rs Users'])) {
$totalRows_rsUsers = $_GET['totalRows_rsUsers'] ;
} else {
$all_rsUsers = mssql_query($query_rsUsers );
$totalRows_rsUsers = mssql_num_rows($all_rsUser s);
}
$totalPages_rsUsers = ceil($totalRows_rsUsers/$m axRows_rsU sers)-1;
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html><!-- InstanceBegin template="/Templates/templ ate.dwt.ph p" codeOutsideHTMLIsLocked="f alse" -->
<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> </td>
<td> </td>
</tr>
<?php do { ?>
<tr>
<td><?php echo $row_rsUsers['employee_ass ets']; ?></td>
<td><?php echo $row_rsUsers['pcname_asset s']; ?></td>
<td><?php echo $row_rsUsers['model_assets ']; ?></td>
<td><?php echo $row_rsUsers['manufac_asse ts']; ?></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 );
?>
Warning: mssql_select_db(): supplied argument is not a valid MS SQL-Link resource in C:\Web Services\Apache Group\Apache2\htdocs\itass
Warning: mssql_query(): supplied argument is not a valid MS SQL-Link resource in C:\Web Services\Apache Group\Apache2\htdocs\itass
Fatal error: Call to undefined function mssql_error() in C:\Web Services\Apache Group\Apache2\htdocs\itass
My connection to the DB seems to work fine. Here is the script...
<?php require_once('connection.p
<?php
$maxRows_rsUsers = 10;
$pageNum_rsUsers = 0;
if (isset($_GET['pageNum_rsUs
$pageNum_rsUsers = $_GET['pageNum_rsUsers'];
}
$startRow_rsUsers = $pageNum_rsUsers * $maxRows_rsUsers;
mssql_select_db($database_
$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_r
$row_rsUsers = mssql_fetch_assoc($rsUsers
if (isset($_GET['totalRows_rs
$totalRows_rsUsers = $_GET['totalRows_rsUsers']
} else {
$all_rsUsers = mssql_query($query_rsUsers
$totalRows_rsUsers = mssql_num_rows($all_rsUser
}
$totalPages_rsUsers = ceil($totalRows_rsUsers/$m
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html><!-- InstanceBegin template="/Templates/templ
<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> </td>
<td> </td>
</tr>
<?php do { ?>
<tr>
<td><?php echo $row_rsUsers['employee_ass
<td><?php echo $row_rsUsers['pcname_asset
<td><?php echo $row_rsUsers['model_assets
<td><?php echo $row_rsUsers['manufac_asse
<td><?php echo $row_rsUsers['notes_assets
<td><?php echo $row_rsUsers['date_assets'
<td><a href="update.php?id_assets
<td><a href="delete.php?id_assets
</tr>
<?php } while ($row_rsUsers = mssql_fetch_assoc($rsUsers
</table>
<!-- InstanceEndEditable --></td>
</tr>
</table>
</body>
<!-- InstanceEnd --></html>
<?php
mssql_free_result($rsUsers
?>
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).
$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\itass ets\test.p hp on line 10
This shows the connection has not been established
This shows the connection has not been established
ASKER
Hsre is connection.php
<?php
# FileName="Connection_php_m ssql.htm"
# Type="MSSQL"
# HTTP="true"
odbc_connect("Assets","sa" ,"password ");
?>
<?php
# FileName="Connection_php_m
# Type="MSSQL"
# HTTP="true"
odbc_connect("Assets","sa"
?>
ASKER
I forgot some variables.
<?php
# FileName="Connection_php_m ssql.htm"
# Type="MSSQL"
# HTTP="true"
$database_assets = "assets";
$assets = odbc_connect("Assets","sa" ,"Th3Dever ");
?>
<?php
# FileName="Connection_php_m
# Type="MSSQL"
# HTTP="true"
$database_assets = "assets";
$assets = odbc_connect("Assets","sa"
?>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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\itass ets\connec tion.php on line 10
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\itass
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\SQLEXP RESS","MyU ser","MyPw d");
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.
-------------------------- ---------- ---------- ---------- ----
--------------------------
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\SQLEXP
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.
--------------------------
ASKER
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\itass ets\test.p hp on line 13
Warning: mssql_query() [function.mssql-query]: Query failed in C:\Web Services\Apache Group\Apache2\htdocs\itass ets\test.p hp on line 13
Fatal error: Call to undefined function mssql_error() in C:\Web Services\Apache Group\Apache2\htdocs\itass ets\test.p hp 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_E RROR);
?>
And here is line 13:
$rsUsers = mssql_query($query_limit_r sUsers, $assets) or die(mssql_error());
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\itass
Warning: mssql_query() [function.mssql-query]: Query failed in C:\Web Services\Apache Group\Apache2\htdocs\itass
Fatal error: Call to undefined function mssql_error() in C:\Web Services\Apache Group\Apache2\htdocs\itass
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(
?>
And here is line 13:
$rsUsers = mssql_query($query_limit_r
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!
ASKER
It appears I have to play with mssql queries a bit, but its up an running. Thanks.
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 ?