Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #14792
| From | Jerry Stuckle <jstucklex@attglobal.net> |
|---|---|
| Newsgroups | comp.lang.php |
| Subject | Re: Error Connectivity with MS Sql-Server 2012 |
| Date | 2015-01-01 23:28 -0500 |
| Organization | A noiseless patient Spider |
| Message-ID | <m856pg$mmj$1@dont-email.me> (permalink) |
| References | <2d5611ac-6526-4082-bef7-f92c23018243@googlegroups.com> |
On 1/1/2015 11:19 PM, jalaf28@gmail.com wrote:
> Hello Group,
>
> i have facing a problem with the php connectivity to the Ms Sql-server. i worked on a project for my lab its works fine with My-Sql(database) but now moved to My-sql server(database) to MS-Sql server 2012 (database) and getting an error while fetching the record from table.
>
> Error :
> "Array ( [0] => Array ( [0] => 42S02 [SQLSTATE] => 42S02 [1] => 208 [code] => 208 [2] => [Microsoft][SQL Server Native Client 11.0][SQL Server]Invalid object name 'usr'. [message] => [Microsoft][SQL Server Native Client 11.0][SQL Server]Invalid object name 'usr'. ) )"
>
> if i am using the system table then its works but user-define table are generating error.
>
> here is the code
>
> file name : "conn.php"
>
> [Code]
>
>
> <?php
> $server="xxx-server\SQLEXPRESS";
>
> $conninfo=array("Database"=>"master");
>
> $conn=sqlsrv_connect($server,$conninfo);
>
> if($conn)
> {
> echo("Connection Establish. <br />");
> }
> else
> {
> echo "Could not established the connection <br />";
> die(printr(sqlsrv_errors(),true));
> }
>
> $tmt="select * from usr";
>
> $stmt=sqlsrv_query($conn,$tmt);
>
> if($stmt)
> {
> echo "Statement Executed";
> }
> else
> {
> die(print_r(sqlsrv_errors(),true));
> }
>
> error_reporting(E_ALL);
>
>
> echo "<table border='1'>";
>
> while( $row= sqlsrv_fetch_array($stmt))
> {
> echo "<tr><td>". $row[0]."</td>";
> echo "<td>".$row[1]."</td></tr>";
>
> }
> echo "</table>";
> sqlsrv_free_stmt($stmt);
> sqlsrv_close($conn);
> ?>
>
>
> What i am doing wrong here please help me.
>
>
> Thanks
>
It's been a while since I've used SQL Server, but I think your problem
is shown by the message "Invalid object name 'usr'.".
Are you sure there is a table or view named "usr" in the "master" database?
BTW - you should never use die() or exit() in a PHP web script on a
production system. This causes all processing of the page to terminate
immediately, resulting in invalid html.
Rather, test for an error, and if one occurs, branch around all code
which depends on the call succeeding. You can do this with if()
statements or by throwing an exception.
--
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex@attglobal.net
==================
Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Error Connectivity with MS Sql-Server 2012 jalaf28@gmail.com - 2015-01-01 20:19 -0800
Re: Error Connectivity with MS Sql-Server 2012 Jerry Stuckle <jstucklex@attglobal.net> - 2015-01-01 23:28 -0500
Re: Error Connectivity with MS Sql-Server 2012 jalaf28@gmail.com - 2015-01-01 21:07 -0800
Re: Error Connectivity with MS Sql-Server 2012 Jerry Stuckle <jstucklex@attglobal.net> - 2015-01-02 08:39 -0500
Re: Error Connectivity with MS Sql-Server 2012 jalaf28@gmail.com - 2015-01-05 00:49 -0800
Re: Error Connectivity with MS Sql-Server 2012 Jerry Stuckle <jstucklex@attglobal.net> - 2015-01-05 08:31 -0500
csiph-web