I am working with a database that must not be modified by our code and another database on the same server set up specifically to fascilitate our needs in that regard. Some uses of the latter (let's call it db2) depend on keeping db2 up to date with (what we'll call) db1, which is mostly handled through scheduled jobs with stored procedures on db2 which use functions also on db2. For a simplified example,
INSERT INTO [db2].[dbo].[lateitems] (orderid, description, originalduedate)
SELECT orderid,
description,
originalduedate
FROM ha_lateorders() lo
WHERE NOT EXISTS (SELECT orderid
FROM [db2].[dbo].[lateitems] li
WHERE li.orderid = lo.orderid;
Which calls a function like,
SELECT orderid,
description,
originalduedate
FROM [db1].[dbo].[orderitems] oi
WHERE originalduedate < GETDATE()
AND originalduedate > DATEADD(week, -1, GETDATE())
(The actual queries are more complex but these snippets demonstrate where the cross-database query takes place.)
It would be beneficial to call one such stored procedure each time one of our php pages accesses [db2].[dbo].[lateitems], but I don't currently know how to set up to run the lateorders function, with its cross-database query, from a php connection to db2. Is it possibly and, if so, how?
This is a SQL Server database, accessed with php8/sqlsrv.
I have tried to identify necessary user permissions, but so far any attempt to execute that function from php has failed. The same user can successfully run the procedure and function when directly logged into the database.
Never mind, I found the solution. Thought I should add it here for anyone who trips over this in future.
It was actually a simple oversight. We had not granted SELECT permission on one of the tables in db1.
Let that be a lesson to me, to always check permissions first!
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Find the answer in similar questions on our website.
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.
PHP (from the English Hypertext Preprocessor - hypertext preprocessor) is a scripting programming language for developing web applications. Supported by most hosting providers, it is one of the most popular tools for creating dynamic websites.
The PHP scripting language has gained wide popularity due to its processing speed, simplicity, cross-platform, functionality and distribution of source codes under its own license.
https://www.php.net/
Welcome to the Q&A site for web developers. Here you can ask a question about the problem you are facing and get answers from other experts. We have created a user-friendly interface so that you can quickly and free of charge ask a question about a web programming problem. We also invite other experts to join our community and help other members who ask questions. In addition, you can use our search for questions with a solution.
Ask about the real problem you are facing. Describe in detail what you are doing and what you want to achieve.
Our goal is to create a strong community in which everyone will support each other. If you find a question and know the answer to it, help others with your knowledge.