473,574 Members | 2,588 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Making PHP return SQL result to a different page

Hi
I have a Microsoft SQL database I can use (also mySQL, so if you know how to
do this in mySQL that is just as useful). The database can only be accessed
from webpages hosted on the same server as the SQL database because of
firewalling. The database admin doesn't mind me accessing it like this if I
can do it, and they would allow me if the firewall could be changed (which
it can't / won't be). However, I need to get direct access to the database
from a different webserver - there is no way around the firewall, and I
can't put the pages on the same webserver for other reasons which aren't
important.
Anyway, what I thought I could try would be a PHP page on the same webserver
as the SQL database. I could then call this page from other pages elsewhere
on the internet, send the query in a POST or GET string (probably post
because of the greater size), the PHP script then queries the SQL server,
and then somehow returns the result to the original calling page. I can't
really work out how to get the return values back to where they need to be,
although I thought putting them in a standard array rather than as database
objects would be easier.
The main problem i'm having is how to return the values to the other page
without calling away from that original page, and how to get the output into
an array or something I can use.
Basically, I would have a script on the server called say SQLinterp.php and
the calling page of mypage.php. These would work something like as follows:

SQLinterp.php:
>>>>>>>> Read in the query from POST data
Verify and then execute the query on the SQL server
Get the return values, put them into some sort of array
Somehow (magic?) get this array back for use in the other page
<<<<<<<<<<<<

mypage.php>>>>>>>>

Draw page headers.......
Query database for some values
Go through and use the database values for various constructions of the page
and tables
More queries
More use of the data
End of page
<<<<<<<<<<<<

Now, what I though I may be able to do is include this as an 'include'
file,so it just executes the query inline and the array it creates, or even
just the normal result, is accessible normally. There is a complication
though, in that I also need this (or a slightly modified version) to
function when called from a C++ application, so simply including it would
not help for this case.
Any ideas greatly appreciated.
Thanks

David


Jul 16 '05 #1
4 6740
David Walker wrote:
Hi [...]SQLinterp.ph p:
>>>>>>>>>Read in the query from POST data
Verify and then execute the query on the SQL server
Get the return values, put them into some sort of array
Somehow (magic?) get this array back for use in the other page
<<<<<<<<<<<<

mypage.php>>>>>>>>>

Draw page headers.......
Query database for some values
Go through and use the database values for various constructions of the page
and tables
More queries
More use of the data
End of page
<<<<<<<<<<<<


Have SQLinterp.php return the data as a XML/HTML text only file,
then parse it in mypage.php or the C++ application
SQLinterp.php
<?php
// read the database
// and output something like this
echo "
<data>
<row><id>1</id><name>David</name></row>
<row><id>4</id><name>hexkid </name></row>
</data>
";
?>
mypage.php
<?php
// ...
$data = implode('',
file('http://database.server/SQLinterp.php?' .
'q="select id, name from users"')
);
// and now parse $data
// ...
?>

HTH

--
"Yes, I'm positive."
"Are you sure?"
"Help, somebody has stolen one of my electrons!"
Two atoms are talking:
Jul 16 '05 #2
> Have SQLinterp.php return the data as a XML/HTML text only file,
then parse it in mypage.php or the C++ application


Ahhh - thanks for that, never thought to do it that way.

David
Jul 16 '05 #3
hex kid wrote:
SQLinterp.php
<?php
// read the database
// and output something like this
echo "
<data>
<row><id>1</id><name>David</name></row>
<row><id>4</id><name>hexkid </name></row>
</data>
";
?>
mypage.php
<?php
// ...
$data = implode('',
file('http://database.server/SQLinterp.php?' .
'q="select id, name from users"')
);
// and now parse $data
// ...
?>


or easier...
SQLinterp.php
<?php
$data = array();
// Fill $data with rows from your query
echo serialize($data );
?>

mypage.php
<?php
$data = trim(implode('' ,
file('http://database.server/SQLinterp.php?' .
'q="select id, name from users"')
));
$data = unserialize($da ta);

// Work with $data, no parsing needed :-)
?>

--
James Sleeman
Gogo:Code http://www.gogo.co.nz/
Email domain : gogo.co.nz see user in from header!
Jul 16 '05 #4
James Sleeman wrote:
[...]
or easier... [edited] use serialize() and unserialize()


wow! very much better :)

--
"Yes, I'm positive."
"Are you sure?"
"Help, somebody has stolen one of my electrons!"
Two atoms are talking:
Jul 16 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

22
9916
by: Bernard Fields | last post by:
Greets, all. As the title suggests, I'm trying to make a maze. Specifically, it's a top-down, 2-d maze, preferably randomly generated, though I'm willing to forego that particular aspect as this point. I've done many, many web-searches, but nothing that I've found so far has provided any clues....
1
4158
by: Kenneth McDonald | last post by:
I'm working on the 0.8 release of my 'rex' module, and would appreciate feedback, suggestions, and criticism as I work towards finalizing the API and feature sets. rex is a module intended to make regular expressions easier to create and use (and in my experience as a regular expression user, it makes them MUCH easier to create and use.) ...
7
4001
by: Christopher Jeris | last post by:
I am relatively new to JavaScript, though not to programming, and I'm having trouble finding the idiomatic JS solution to the following problem. I have a table with (say) fields f1, f2, f3. I do a database query and what I wind up with is a structure Q of arrays: Q.f1 is field f1 in row n, Q.f1.length == Q.f2.length == Q.f3.length is the...
6
3432
by: Bruce W.1 | last post by:
The intent of my web service is an RSS feed from a blog. Originally I used a StringBuilder to make the XML and returned a string from the webmethod. But this doesn't display properly in IE. So now I'm trying an XmlTextWriter instead. I whipped-up another webservice based on this:...
2
4658
by: Rhino | last post by:
I am trying to verify that I correctly understand something I saw in the DB2 Information Center. I am running DB2 Personal Edition V8.2.1 on Windows. I came across the following in the Info Center: To return a result set from a procedure to the originating application, use the WITH RETURN TO CLIENT clause. When WITH RETURN TO CLIENT is...
18
2251
by: Ed Jay | last post by:
<disclaimer>js newbie</disclaimer> My page has a form comprised of several radio buttons. I want to poll the buttons to determine which button was selected and convert its value to a string. I then want to use the string on the same page. My script is: function checkRadio(field) { for(var i=0; i < field.length; i++) {
5
2466
by: bsmith1111 | last post by:
I'm working on a simple calculator similar to the MS Calculator in visual c++ 6.0. I'm trying to teach myself the visual aspect of c++ on my own time, so I've decided to jump right into a program after reading through a lot of material that has gotten me familiar with it. I have a result edit box at the top of the window which holds whatever...
351
12863
by: CBFalconer | last post by:
We often find hidden, and totally unnecessary, assumptions being made in code. The following leans heavily on one particular example, which happens to be in C. However similar things can (and do) occur in any language. These assumptions are generally made because of familiarity with the language. As a non-code example, consider the idea...
2
2023
by: gen_tricomi | last post by:
THE IMPORTANCE OF MAKING THE GOOGLE INDEX DOWNLOADABLE I write here to make a request on behalf of all the programmers on earth who have been or are intending to use the Google web search API for either research purposes or for the development of real world applications, that Google make their indexes downloadable. Currently...
0
7814
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8075
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8109
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6471
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5632
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5316
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3752
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2253
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1356
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.