473,788 Members | 2,743 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 6751
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
9936
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
4184
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.) I'm still working on formal documentation, and in any case, such documentation isn't necessarily the...
7
4019
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 record count of the query. (This representation is of course backwards, but that's what...
6
3440
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: http://www.codeproject.com/aspnet/RSSviaXmlTextWriter.asp?print=true This example isn't set up strictly as a webservice. It seems to output to an aspx...
2
4673
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 specified on a result set, no nested procedures can access the result set.
18
2270
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
2477
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 is being typed in via the numerical buttons and arithmetic buttons (+, -, *, /). Each numerical...
351
13148
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 that the faulty code is written by blackguards bent on foulling the language. The term...
2
2044
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 application programmers using the Google web search API are
0
9656
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9498
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10370
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10177
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9969
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8995
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7519
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5402
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4074
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

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.