This topic is locked
[SOLVED]

 Events page Query different Database

6/22/2012 10:57:07 AM
PHPRunner General questions
W
wildwally author

Looking for guidance on how to query a second database from the events page. I've tried creatign a second $conn calling it $conn2 and calling it in my event. However, everything else within PHPRunner forces/uses $conn. So there has to be a way that will allow me to run a simple query on another database and display the results in a custom table for my user to see and reference.

C
cgphp 6/22/2012

Post your code.

W
wildwally author 6/22/2012


function db_connect()

{

global $host,$user,$pwd,$dbname,$host2,$user2,$pwd2,$dbname2;



$connectionInfo = array("Database"=>$dbname, "PWD" => $pwd, "UID" => $user);

$conn = sqlsrv_connect($host, $connectionInfo);

$connectionInfo2 = array("Database"=>$dbname2, "PWD" => $pwd2, "UID" => $user2);

$conn2 = sqlsrv_connect($host2, $connectionInfo2);

if(!$conn)

triggerErrorMSSQL();
return $conn;

if(!$conn2)

triggerErrorMSSQL();
return $conn2;

}


This is what I changed within the dbconnection.mssql.sqlsrv.php
then in the events I'm simply using the



Global $conn2


However I get this error
Fatal error: Call to a member function Execute() on a non-object in C:\Users\wally\Documents\PHPRunnerProjects\NewQDM\output\include\dbconnection.mssql.win.php on line 39
which the line of code is:



function db_query($qstring,$conn)

{

global $strLastSQL,$dDebug;

if ($dDebug===true)

echo $qstring."

";

$strLastSQL=$qstring;

try{

return $conn->Execute($qstring); //<---------------------------------------------Error Here---------------------------------------<<<<<<<<

} catch(com_exception $e)

{

trigger_error($e->getMessage(),E_USER_ERROR);

}
}


Which tells me PHPRunner is trying to revert back to the $conn. So instead of trying to creat a bunch of alternate code my next line of thought is to hard code the connection, Query and Close code within the event and not run and PHPRunner functions. But I need some guidance.

W
wildwally author 6/22/2012
Sergey Kornilov admin 6/22/2012



Can this be converted to work in PHP Runner?
http://www.asprunner.com/forums/topic/17429-multiple-database-connections/


Yes, simply open connection right where you need it.

global $host,$user,$pwd,$dbname;

$connectionInfo = array("Database"=>$dbname, "PWD" => $pwd, "UID" => $user);

$myconn = sqlsrv_connect($host, $connectionInfo);


Here is a more complete example of connection and query execution:

http://www.php.net/manual/en/function.sqlsrv-query.php

W
wildwally author 6/23/2012

Why would I see this error? The SQL server Dll drivers should already be in operation since PHPRunner is already using them, correct?
Fatal error: Call to undefined function sqlsrv_connect()

J
Jane 6/25/2012

Hi,
this error means that your PHP is not configured properly. You need the SQL server extension in PHP:

http://www.php.net/manual/en/book.sqlsrv.php

W
wildwally author 6/25/2012

I don't understand why this is required if PHPRunner is using the same connection code within it's functions in the database connection files. One would think this would already be setup and working??
So I'm trying to follow along and I've dropped the dll files into the PHP Extensions folder. I've modified the extension section within the PHP.ini file to call the SQLSRV dll's as outlined in the instructions; however, I'm still not having any luck. I've restarted the service as instruc ted and still nothing.
Any better instructions you can provide?

Sergey Kornilov admin 6/25/2012

Most likely PHPRunner is not using sqlsrv functions. PHPRunner comes with three SQL Server connection interfaces and uses the one that is available on your server: mssql functions, sqlsrv_ functions or COM-based ADODB.Connection method. You need to find what PHP SQL Server functions are available on your web server and use them.
Contact your web hosting company for more info on this.

W
wildwally author 6/25/2012

there is no host. I'm just trying to run this from my computer and connect to another instance of SQL on another server. I know the connection works from PHPRunner if I change the database source - therefore ruling out any issues outside of the SQLSRV dll's.