/    Sign up×
Community /Pin to ProfileBookmark

Long query string

Hi,
I want to send lots of data to MySQL database through a PHP file. I know the standard way to do that is:
[url]http://server.com/file.php?var1=4&var2=12&var3=3[/url]
Now if I have like 200 variables to send, the string would be too long and it wouldnt work. I could split it into 10 requests each handling 20 variables, but that would be inefficient, i think. What’s the workaround? ?

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@NogDogJan 18.2010 — Assuming you want to submit it from within a PHP script, use the [url=http://php.net/curl]cURL[/url] functions to send it as POST data.
Copy linkTweet thisAlerts:
@alexxz4authorJan 18.2010 — Well, actually, I am going to use client-side C# code to construct the query string and update a remote MySQL database.

Which cURL function would I use? Sorry for bothering you...
Copy linkTweet thisAlerts:
@JerailJan 18.2010 — Wouldn't it be more efficient to POST the data, or even use cookies or sessions?
Copy linkTweet thisAlerts:
@alexxz4authorJan 18.2010 — But isnt POST used from an HTML form? and Im not using any form.

What I need to do in more detail is: I have a tile-based game where there is a large 2D array of tiles which is stored in a database. After some time, some tiles (there can be hundreds) are changed in game, and I want my program to update the database also.
[code language="C#"]
WebClient Client = new WebClient();
string path="http://server.com/file.php?";
int cnt=0;
foreach(Tile tile in tiles){
path+="x"+cnt+"="+tile.X+"&y"+cnt+"="+tile.Y+"&v"+cnt+"="+tile.Value+"&";
cnt++;
}
path=path.Substring(0,path.Length-1);
Stream strm = Client.OpenRead(path);
StreamReader sr = new StreamReader(strm);
string line;
line=sr.ReadLine();
[/code]

Obviously, the path in the above code would be rejected by PHP if there are more than 20 (or so) tiles.
Copy linkTweet thisAlerts:
@NogDogJan 19.2010 — I'm not a C# coder, but see if this is something you could use:

http://msdn.microsoft.com/en-us/library/debx8sh9.aspx

You would want to follow the option where you set the post option:
<i>
</i>request.Method = "POST";


The PHP file you call from it would need to be adapted to use $_POST variables instead of $_GET.
Copy linkTweet thisAlerts:
@alexxz4authorJan 19.2010 — ok, got it.

Thanx.
×

Success!

Help @alexxz4 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...