Re: [PHP] url obfuscation

2006-07-07 Thread Anas Mughal

My URLs are constant. They are not changing.
All my dynamic pages are indexed nicely on Google.

I agree that a computerized screen scrapper could still screen scrap most of
my site. However, a simple script that attempts to bump up the identifier of
a resource in a URL, would not work. Here is example:

http://mydomain.com/view_resource.php?id=1
http://mydomain.com/view_resource.php?id=2
http://mydomain.com/view_resource.php?id=3
http://mydomain.com/view_resource.php?id=4

That would not work because my IDs are not sequential.

Any thoughts...




On 7/7/06, Richard Lynch <[EMAIL PROTECTED]> wrote:


On Thu, July 6, 2006 12:00 pm, Anas Mughal wrote:
> I have encrypted the values -- not the keys. With this approach, I
> presume I
> have made it harder for anyone trying to screen scrap my data. (It is
> not
> possible to write a script that would loop over my pages.)

Unless you are using an always-changing value for the value, then the
screen-scraper doesn't really give a damn whether the value is:
2
avpu8e9hgre98gh9erhb549hgt2395tybnsdibnusreiobnwre9pg8h25490t8

It's all the same to a computer.

If you ARE using always-changing URLs, then the search engines are
never gonna find your pages, which seems like an odd goal to me.

--
Like Music?
http://l-i-e.com/artists.htm






--
Anas Mughal


[PHP] phpdocwriter

2006-07-07 Thread Leonard Burton

HI All,

Has anyone used phpdocwriter?

Does anyone know how to get it to work with OO 2.0?

It does not seem to work and the export.sh is specific to OO1.1.1.

Does this seem to be a mostly dead project?  I didn't see much on the
forums linked to from
http://phpdocwriter.sourceforge.net/links.php?lang=en

Any ideas?

Thanks.

--
Leonard Burton, N9URK
[EMAIL PROTECTED]

"The prolonged evacuation would have dramatically affected the
survivability of the occupants."

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Sanity checker?

2006-07-07 Thread Ezra Nugroho
Php experts everywhere,

This is a response to an old thread about a php audit tool.

I just want to announce a simple tool for that. It is not super smart
yet, but it is easily extensible. 

Please check it out, and provide me with suggestions.
http://developer.spikesource.com/projects/phpsecaudit

I need a lot of help identifying function calls that need to be handled
with cautions. 

Thank you

--
Ezra Nugroho
http://ez.spikesource.com



On Thu, 2006-05-04 at 14:44 -0500, Jay Blanchard wrote:
> [snip]
> Have you ever seen things like
> 
> for ($i = 0; $i < count($some_array); $i++) {
>   //do stuff
> }
> 
> Do you know how slow it is if $some_array gets big compared to 
> 
> $array_count = count($some_array);
> for ($i = 0; $i < $array_count; $i++) {
>   //do stuff
> }
> [/snip]
> 
> The thing is this; there are lots of cases such as the one above that
> someone would have to code in order to make the tool worthwhile. It
> sounds like a good project for a large group of folks. We have headed
> down the road a couple of times on things like this and the problem
> always comes down to manpower. Start a project at SF or FM that maybe
> does a couple of basic things and hope that it grows from there.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Chnage Management in PHP aka version control?

2006-07-07 Thread Richard Lynch
On Wed, July 5, 2006 10:40 am, [EMAIL PROTECTED] wrote:
> I don't know about you, Jay, but all we really want to do is keep a
> record of revisions and be able to 'diff' between them and have the
> files lock so if someone tries to open the file and it's already open,
> that the user is alerted and allowed to open read-only if they desire.

I *much* prefer the CVS/subversion paradigm of concurrent changes, but
if the above is what you want, perhaps you should look into
SourceSafe.

NOTE:
SourceSafe in the 80s on Mac PPC *ate* two of my projects when
goofballs added ".doc" files as text.

I'll never ever ever use this product again, no matter how many people
tell me it's been fixed.

YMMV

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] global class instance

2006-07-07 Thread Richard Lynch
On Wed, July 5, 2006 3:32 pm, KermodeBear wrote:
>>> i don't want to:
>>>- or use a::print

> $myFoo =& Singleton::getFoo();

What's wrong in this picture? :-)

As far as I can tell, the original poster shouldn't be using PHP,
since he wants the language to have some kind of implicit "$this"

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Web service in PHP

2006-07-07 Thread Richard Lynch
On Fri, July 7, 2006 3:39 am, Pham Huu Le Quoc Phuc wrote:
> I want to build a Web Service in PHP.
> Could you give me some explain about this problem.
> Have any framework of Web service in PHP?

One framework:
http://php.net/soap

Roll your own framework:
http://php.net/sockets

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] running multiple updates on a single line

2006-07-07 Thread Richard Lynch
On Mon, July 3, 2006 8:29 pm, Ryan A wrote:
> in phpmyadmin, in the SQL part where you can write a
> query if I have a double update such as this:
>
> it works without a problem as I am ending each sql
> statement with a simicolon, but in my scripts when I
> try to run multiple updates in a single line
>
> eg:
> $xyz="update xyz set id=1 where id=0;update xyz set
> id=3 where id=2;";
>
> it does not work... any idea why?

PHP MySQL client disallows that as a crude stop for some SQL injection
attacks.

I believe that upcoming MySQL client libraries may put it back in.

mysqli might even have it already.

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Bitwise operators and check if an bit is NOT within the flag.

2006-07-07 Thread Richard Lynch
On Tue, July 4, 2006 7:35 am, Mathijs wrote:
> //Do if VALIDATE_CHECK1 is set BUT NOT when VALIDATE_CHECK3 is set.
> if ($flag2 & self::VALIDATE_CHECK1 && $flag2 & ~self::VALIDATE_CHECK3)

Did you check operator precedence for & versus &&?

Perhaps you just need parentheses...

I'm also not at all sure the ~self::VALIDATE_CHECK3 is doing what you
want...  Echo that out and see if it's the number you would expect...

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] url obfuscation

2006-07-07 Thread Richard Lynch
On Thu, July 6, 2006 12:00 pm, Anas Mughal wrote:
> I have encrypted the values -- not the keys. With this approach, I
> presume I
> have made it harder for anyone trying to screen scrap my data. (It is
> not
> possible to write a script that would loop over my pages.)

Unless you are using an always-changing value for the value, then the
screen-scraper doesn't really give a damn whether the value is:
2
avpu8e9hgre98gh9erhb549hgt2395tybnsdibnusreiobnwre9pg8h25490t8

It's all the same to a computer.

If you ARE using always-changing URLs, then the search engines are
never gonna find your pages, which seems like an odd goal to me.

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] uploading and extracting zip files

2006-07-07 Thread Richard Lynch
On Tue, July 4, 2006 7:26 pm, Schalk wrote:
> Can someone please point me to a tutorial or open source 'library'
> that
> will explain how one can upload a .zip file and then extract it's
> contents and store this on the server and/or database using PHP.
> Basically the same way as one can upload and install components etc.
> with Joomla. Thanks!

http://php.net/zip

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] url obfuscation

2006-07-07 Thread Richard Lynch
On Thu, July 6, 2006 11:49 am, Dan McCullough wrote:
> Looking for a good way to obfuscation the name value pairs in a URL,
> so it might be something like
> http://www.domain.com/page=fjdsaflkjdsafkfjdsakfjdsalkfjsda983dsf or
> something like that, I was looking at base64_encode, but was wondering
> what others might do or use.  It doesnt have to be super secure, but I
> would still like the information to not be really visable.

Bad Idea.

Your URLs will get much too long, and GET data can be limited, and
you'll hit that limit if you keep this up...

If the data shouldn't be visible, put it in $_SESSION

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Problem using fgetcsv()

2006-07-07 Thread Richard Lynch
On Thu, July 6, 2006 11:54 am, Don wrote:
> I have a CSV file, comma delimited with the data enclosed by double
> quotes.
>
> I am using the fgetcsv() function to read and into an array and update
> a
> database.  It works great except for the odd record. After
> investigating, I
> have ascertained that it is due to a backslash character in the data
> which
> fgetcsv() cannot parse properly.  I don;t see anyway around this using
> fgetcsv().  Has anyone written a custom routine for this?
>
> Code Snippet
> ---
> $vvFile = 'myfile.csv';
> $fph = fopen($vvFile,"r")
> if ($fph) {
> while (($data = fgetcsv($fph,4096,',','"')) !== FALSE) {M

You *MUST* use:
http://php.net/mysql_real_escape_string
on each element of the array before cramming it into MySQL.

> // Insert fields from array '$data' to my MySQL database -
> will fail
> on bad data
> }
> fclose($fph);
> }
>
> Sample Data
> --
> "123456","135679048754","7154904875","HD INDOOR INSECT KILR 33 OZ
> 6","EA"
> "654321","246809052607","7154905260","59-2 CACTUS & SUCCULENTS
> \","EA"

The \ is special to MySQL (and PHP) but not CSV.
So your problem is not with CSV -- It's with MySQL input routines.
See above.

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Startinga shell process with a life of its own

2006-07-07 Thread Richard Lynch
On Thu, July 6, 2006 9:29 pm, John Gunther wrote:
> Which PHP method allows me to start a shell process from a web page
> script and let it proceed to its conclusion even though I end the
> page.
> Most of the various execute functions seem to wait for the process to
> finish before PHP continues. I don't understand the ones with
> open/close
> functions. Will opening a process and failing to close it let it run
> after the page ends? Will failing to close cause other problems? Can
> you
> point me to example code? The shell commands I want to run are
> typically
> themselves PHP programs whose execution time is far too long to
> complete
> in a browser context.

On some machines, on some OSes, in some configurations, with some
commands, tacking "&" onto the end of what you exec, will sometimes
"work"...

I would recommend, however, that you re-structure things slightly so
that the Architecture is more like this:

User visits web page.
Page generates a database record of what needs to be done.
Page finished.


CRON JOB:
Look in task list of what needs doing, and do some of them.
Make sure only one job is done at a time, or whatever race conditions
are handled here.

I've done projects both ways, and always end up frustrated with the
"PHP attempts to background a process" and the "Task List + Cron"
always works out far far better.

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Video in PHP

2006-07-07 Thread Richard Lynch
On Fri, July 7, 2006 11:23 am, Leonard Burton wrote:
> I am researching setting up an application in PHP where it would play
> various videos.
>
> I played with PHP and Totem but it didn't work exactly as planned.
>
> This code got the videos playing
> 
> exec("totem --fullscreen million_dollar_weekend.mpeg");
> exec("totem --fullscreen we_use_power_edit.mp4");
> 
>
> The problem here is that when the video stops totem stays open and
> therefore my script does not realize that it is time to play the next
> video.
>
> Does anyone have any ideas how to get them to stop properly?

man totem *MIGHT* list a command line argument to make it play one
video and quit...

Or you might contact the totem team and get them to add it for you.

> Is there another/better player than totem? Videolan does not have the
> level of command line control that totem does.
>
> Is there a pcntl function that might do the trick?

You could run totem in the background, and poll the process PID and
see how "busy" it is, maybe...

> I could keep a list of the videos and lengths and then have my script
> issue a kill comand once the length of time plus some play time has
> ellapsed.

This is hinky, as the user could easily "pause" the video, presumably...

Random Thought:
Perhaps PHP GTK http://gtk.php.net already has a video player of some
kind with "hooks" for you to know when the video is finished.

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] RE: [PHP-WIN] Dynamic HTML table sort with PHP

2006-07-07 Thread Vandegrift, Ken
Thanks for the tip!

This works great as I only need a single column sort :) 


Ken Vandegrift
[EMAIL PROTECTED]
Web Administrator
Sharis Mgmt. Corp

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] 
Sent: Friday, July 07, 2006 10:01 AM
To: php-general@lists.php.net
Subject: Re: [PHP-WIN] Dynamic HTML table sort with PHP

If you're only sorting by one column at a time (not adding to a column
sort list) then you can do something like this:

$ascdesc = ($_GET['sortcol'] == 'colA' AND $_GET['ad'] == 'ASC') ?
'DESC' : 'ASC'; echo "ColA\n";

$ascdesc = ($_GET['sortcol'] == 'colB' AND $_GET['ad'] == 'ASC') ?
'DESC' : 'ASC'; echo "ColA\n";

$ascdesc = ($_GET['sortcol'] == 'colC' AND $_GET['ad'] == 'ASC') ?
'DESC' : 'ASC'; echo "ColA\n";

In this case, the only time you want a descending sort is when the
column being sorted is the current column (who's HREF is being output)
and the current sort value is ASC.  If current sort value is blank,
it'll default to ascending.

And if you're not familiar with that $var = (condition) ? 'value1' :
'value2'; syntax, look up ternary operations.  It's just a short hand
way of saying "if this is true, use this value, else use this second
value".

I also did code once where each column you clicked got added to the sort
list.  So if you clicked column B, that became primary sort.  If you
clicked on column C after that, then C became the primary sort and B was
the secondary sort.  On top of that I did thte ASC/DESC thing too.

Just a matter of working out the logic, but yes, you can do it all in
PHP.

-TG


= = = Original message = = =

Good Day List,
 
Does anybody know of a pure PHP way to make table header cells trigger a
column sort?
 
If I have a table header that contains a link that when clicked
resubmits the page to itself with the proper sort query variables (e.g.
index.php?sortBy=ORDER_ID&sortOrder=ASC), I want PHP to rewrite the
sortOrder query string to be "sortOrder=DESC" and then "sortOrder=ASC"
the next time column heading is clicked.  This way, the column will sort
like windows columns and users will feel "at-home" with the process.
 
I can write some JavaScript that will dynamically rewrite the href
attribute of the link, but I was hoping for a pure PHP solution in case
JavaScript is disabled.
 
Thanks.
 
Ken Vandegrift
[EMAIL PROTECTED]  Web Administrator
Sharis Mgmt. Corp


___
Sent by ePrompter, the premier email notification software.
Free download at http://www.ePrompter.com.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Video in PHP

2006-07-07 Thread tg-php
Looks like totem supports playlists, why not just generate a playlist and pipe 
that into totem?

And I don't see any obvious documentation without downloading Totem, but you 
might check to see if there's an "exit on end" option that'd return control 
back to PHP if a playlist isn't an option.

Or if you can feed totem a list of files without generating a playlist.  Some 
media players will generate a playlist in memory based on a list of file 
names/paths sent to it rather than loading a text file playlist.

-TG

= = = Original message = = =

Hi all,

I am researching setting up an application in PHP where it would play
various videos.

I played with PHP and Totem but it didn't work exactly as planned.

This code got the videos playing

exec("totem --fullscreen million_dollar_weekend.mpeg");
exec("totem --fullscreen we_use_power_edit.mp4");


The problem here is that when the video stops totem stays open and
therefore my script does not realize that it is time to play the next
video.

Does anyone have any ideas how to get them to stop properly?

Is there another/better player than totem? Videolan does not have the
level of command line control that totem does.

Is there a pcntl function that might do the trick?

I could keep a list of the videos and lengths and then have my script
issue a kill comand once the length of time plus some play time has
ellapsed.

Thanks,

-- 
Leonard Burton, N9URK
[EMAIL PROTECTED]

"The prolonged evacuation would have dramatically affected the
survivability of the occupants."


___
Sent by ePrompter, the premier email notification software.
Free download at http://www.ePrompter.com.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: [PHP-WIN] Dynamic HTML table sort with PHP

2006-07-07 Thread tg-php
If you're only sorting by one column at a time (not adding to a column sort 
list) then you can do something like this:

$ascdesc = ($_GET['sortcol'] == 'colA' AND $_GET['ad'] == 'ASC') ? 'DESC' : 
'ASC';
echo "ColA\n";

$ascdesc = ($_GET['sortcol'] == 'colB' AND $_GET['ad'] == 'ASC') ? 'DESC' : 
'ASC';
echo "ColA\n";

$ascdesc = ($_GET['sortcol'] == 'colC' AND $_GET['ad'] == 'ASC') ? 'DESC' : 
'ASC';
echo "ColA\n";

In this case, the only time you want a descending sort is when the column being 
sorted is the current column (who's HREF is being output) and the current sort 
value is ASC.  If current sort value is blank, it'll default to ascending.

And if you're not familiar with that $var = (condition) ? 'value1' : 'value2'; 
syntax, look up ternary operations.  It's just a short hand way of saying "if 
this is true, use this value, else use this second value".

I also did code once where each column you clicked got added to the sort list.  
So if you clicked column B, that became primary sort.  If you clicked on column 
C after that, then C became the primary sort and B was the secondary sort.  On 
top of that I did thte ASC/DESC thing too.

Just a matter of working out the logic, but yes, you can do it all in PHP.

-TG


= = = Original message = = =

Good Day List,
 
Does anybody know of a pure PHP way to make table header cells trigger a
column sort?
 
If I have a table header that contains a link that when clicked
resubmits the page to itself with the proper sort query variables (e.g.
index.php?sortBy=ORDER_ID&sortOrder=ASC), I want PHP to rewrite the
sortOrder query string to be "sortOrder=DESC" and then "sortOrder=ASC"
the next time column heading is clicked.  This way, the column will sort
like windows columns and users will feel "at-home" with the process.
 
I can write some JavaScript that will dynamically rewrite the href
attribute of the link, but I was hoping for a pure PHP solution in case
JavaScript is disabled.
 
Thanks.
 
Ken Vandegrift
[EMAIL PROTECTED]  
Web Administrator
Sharis Mgmt. Corp


___
Sent by ePrompter, the premier email notification software.
Free download at http://www.ePrompter.com.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Video in PHP

2006-07-07 Thread Leonard Burton

Hi all,

I am researching setting up an application in PHP where it would play
various videos.

I played with PHP and Totem but it didn't work exactly as planned.

This code got the videos playing

exec("totem --fullscreen million_dollar_weekend.mpeg");
exec("totem --fullscreen we_use_power_edit.mp4");


The problem here is that when the video stops totem stays open and
therefore my script does not realize that it is time to play the next
video.

Does anyone have any ideas how to get them to stop properly?

Is there another/better player than totem? Videolan does not have the
level of command line control that totem does.

Is there a pcntl function that might do the trick?

I could keep a list of the videos and lengths and then have my script
issue a kill comand once the length of time plus some play time has
ellapsed.

Thanks,

--
Leonard Burton, N9URK
[EMAIL PROTECTED]

"The prolonged evacuation would have dramatically affected the
survivability of the occupants."

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] combine implode() and array_keys() to get a string of key names

2006-07-07 Thread Janet Valade

Dave M G wrote:


PHP List,

   I've got a series of associative arrays that contain simple string 
values that I want to insert into my database.


   In each array, the names of the keys correspond to the column names 
in the database table. The values stored in the array are, of course, 
the values that I want to insert into the columns.


   So, I want to set up a function where I can pass the array as an 
argument, and it will construct the MySQL statement using the keys for 
column names, and array values for insert  values.


   Within the function, the query looks like this:
   $query = "INSERT INTO table (" . $columns . ") VALUES = (" . $values 
. ")";


   Assuming that the array argument passed to the function is called 
$array, converting the array values to the insert values is pretty easy:

   $values = implode(", ", $array);

   But in the case of using the array keys for column names, it's not so 
easy:

   $columns = implode(", " array->keys($array));

   I know that code above doesn't work, because, as described in the 
manual, array keys returns a list of the numerical indexes along with 
the string indexes. 


Actually, it doesn't matter what the indexes are when you use implode. 
Implode just puts the values into a string. Here's code that will work.


  $field_array = array_keys($fields_form);
  $fields = implode(",",$field_array);
  $values = implode('","',$fields_form);
  $query = "INSERT INTO Table1 ($fields) VALUES (\"$values\")";
  $result = mysqli_query($cxn,$query);

$fields_form is an associative array of all the fields to be entered 
into the database, with the field names as keys and the field values as 
values. This code quotes the values in the $values string in the query, 
as needed if the values are strings.


Janet



Something like this:


Array
(
   [0] => column1
   [1] => column2
   [2] => column3
)

   At least, that's what it looks like if it's just echoed out.

   Is there a way I can strip out the relevant column names to be more 
like this:


"column1, column2. column3"

   Thank you for any advice.

--
Dave M G




--
Janet Valade -- janet.valade.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] combine implode() and array_keys() to get a string of key names

2006-07-07 Thread Dimiter Ivanov

On 7/7/06, Dave M G <[EMAIL PROTECTED]> wrote:

PHP List,

I've got a series of associative arrays that contain simple string
values that I want to insert into my database.

In each array, the names of the keys correspond to the column names
in the database table. The values stored in the array are, of course,
the values that I want to insert into the columns.

So, I want to set up a function where I can pass the array as an
argument, and it will construct the MySQL statement using the keys for
column names, and array values for insert  values.

Within the function, the query looks like this:
$query = "INSERT INTO table (" . $columns . ") VALUES = (" . $values
. ")";

Assuming that the array argument passed to the function is called
$array, converting the array values to the insert values is pretty easy:
$values = implode(", ", $array);

But in the case of using the array keys for column names, it's not
so easy:
$columns = implode(", " array->keys($array));

I know that code above doesn't work, because, as described in the
manual, array keys returns a list of the numerical indexes along with
the string indexes. Something like this:

Array
(
[0] => column1
[1] => column2
[2] => column3
)

At least, that's what it looks like if it's just echoed out.

Is there a way I can strip out the relevant column names to be more
like this:

"column1, column2. column3"

Thank you for any advice.

--
Dave M G

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Well after calling array_keys you have an array with all the keys.
If you implode it the same way like you get the values from the
original array, you will get what you want.
$values = implode(", ", $array);
$keys = array_keys($array);
$columns = implode(", ",$keys);

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] combine implode() and array_keys() to get a string of key names

2006-07-07 Thread Jochem Maas
Dave M G wrote:
> PHP List,
> 
>I've got a series of associative arrays that contain simple string
> values that I want to insert into my database.
> 
>In each array, the names of the keys correspond to the column names
> in the database table. The values stored in the array are, of course,
> the values that I want to insert into the columns.
> 
>So, I want to set up a function where I can pass the array as an
> argument, and it will construct the MySQL statement using the keys for
> column names, and array values for insert  values.
> 
>Within the function, the query looks like this:
>$query = "INSERT INTO table (" . $columns . ") VALUES = (" . $values
> . ")";
> 
>Assuming that the array argument passed to the function is called
> $array, converting the array values to the insert values is pretty easy:
>$values = implode(", ", $array);
> 
>But in the case of using the array keys for column names, it's not so
> easy:
>$columns = implode(", " array->keys($array));
> 
>I know that code above doesn't work, because, as described in the
> manual, array keys returns a list of the numerical indexes along with
> the string indexes. Something like this:
> 
> Array
> (
>[0] => column1
>[1] => column2
>[2] => column3
> )
> 
>At least, that's what it looks like if it's just echoed out.
> 
>Is there a way I can strip out the relevant column names to be more
> like this:
> 
> "column1, column2. column3"
> 
>Thank you for any advice.

I'll assume you 'data' array only contains associative keys for simpilicity,
here we go:

function davesMakeValueSafeForDBInsertionFunc($v)
{
if (is_null($arg)) return 'NULL';
if (is_numeric($arg)) return $arg;

return "'".mysql_real_escape_string($arg)."'";
}

function davesFunkyDBElementQuoterFunc($elName)
{
return "`{$elName}`";
}

$data  = array(
'col1' => 1,
'col2' => null,
'col3' => "yadda yadda",
);

$columns = join(',', array_map('davesFunkyDBElementQuoterFunc', 
array_keys($data)));
$values  = join(',', array_map('davesMakeValueSafeForDBInsertionFunc', $data));
$query   = "INSERT INTO table ($columns) VALUES ($values)";

// tada!

> 
> -- 
> Dave M G
> 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] combine implode() and array_keys() to get a string of key names

2006-07-07 Thread Dave M G

PHP List,

   I've got a series of associative arrays that contain simple string 
values that I want to insert into my database.


   In each array, the names of the keys correspond to the column names 
in the database table. The values stored in the array are, of course, 
the values that I want to insert into the columns.


   So, I want to set up a function where I can pass the array as an 
argument, and it will construct the MySQL statement using the keys for 
column names, and array values for insert  values.


   Within the function, the query looks like this:
   $query = "INSERT INTO table (" . $columns . ") VALUES = (" . $values 
. ")";


   Assuming that the array argument passed to the function is called 
$array, converting the array values to the insert values is pretty easy:

   $values = implode(", ", $array);

   But in the case of using the array keys for column names, it's not 
so easy:

   $columns = implode(", " array->keys($array));

   I know that code above doesn't work, because, as described in the 
manual, array keys returns a list of the numerical indexes along with 
the string indexes. Something like this:


Array
(
   [0] => column1
   [1] => column2
   [2] => column3
)

   At least, that's what it looks like if it's just echoed out.

   Is there a way I can strip out the relevant column names to be more 
like this:


"column1, column2. column3"

   Thank you for any advice.

--
Dave M G

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Web service in PHP

2006-07-07 Thread nicolas figaro

Pham Huu Le Quoc Phuc a écrit :

Hi!
  

Hi,

I want to build a Web Service in PHP.
  

cool !

Could you give me some explain about this problem.
Have any framework of Web service in PHP?

  

could you give us some infos about the "web service" you'd like to build ?

Please help me!
  

N F

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

[PHP] Web service in PHP

2006-07-07 Thread Pham Huu Le Quoc Phuc
Hi!
I want to build a Web Service in PHP.
Could you give me some explain about this problem.
Have any framework of Web service in PHP?

Please help me!

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php