Re: [PHP] confused big time

2004-04-07 Thread Mark Ackroyd
I always found this way of inserting data into a database messy. Here is 
a handy function to do array inserts and it builds the sql for you.

function arrayINSERT($a,$tablename)
{
$sql = INSERT INTO $tablename (;
foreach($a as $key = $value)
{
$sql .= $key .,;
}   
$sql[strlen($sql)-1] = ')';
$sql .=  VALUES (;
foreach($a as $key = $value)
{
if (gettype($value) == 'string')
{   
$sql .= '. addslashes($value) .',;
}
else
{
$sql .= $value .,;
}
}
$sql[strlen($sql)-1] = ')';
return $sql;
}
if you do this :

$a['field1'] = $blah;
$a['field2'] = $here;
$a['field3'] = $etc;
$sql = arrayINSERT($a,tablename);
it builds the sql statement for you.  It covers 99.9% of the inserts 
your likely to need.  I use an update and insert function like this all 
the time. :-)

Mark



Richard Davey wrote:

$sql = 
INSERT INTO
   tablename
   (
field1,
field2,
field3
   )
VALUES
  (
'$blah',
$here',
'$etc'
  )
;
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] confused big time

2004-04-07 Thread Mark Ackroyd
RD That .1% of the time being when you need to insert a value as now() ?
RD (which will break the string check as it'll wrap it with '' which will
RD cause MySQL to insert -00-00 00:00:00) or if it's an enum field
RD with a numeric allowed value? :)
Not really, since you usally format a timestamp into something thats db 
friendly. How many times have you written code where the date 02-01-2004 
  means the 2nd of Jan or the 1st of Feb?. On a MS SQL BOX the best 
format is '01-MAR-2004 12:00:00' which is eval'ed as a string. On mysql 
it's '2004-03-01 12:00:00' if you get into the habbit of *always* 
converting the date into a db friendly string, then you'll never have 
date insert problems and it can be used in the function without issues.

Mark

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


Re: [PHP] confused big time

2004-04-07 Thread Mark Ackroyd
RD But now() IS a DB friendly format for MySQL and is the recommended
RD way of inserting the current time into a datetime or timestamp
RD field.
But what about MsSQL, Oracle and postgres to name a few. I have worked 
on a few projects where you read from one db and load into another db. 
Dates then become the spawn of satan.

RD Converting it to a timestamp/datetime locally first is a waste of
RD processing time IMHO and opens you up to a potential
RD slight)
True that it wastes CPU time, but in todays climate, having developers 
churning out manageable , readable code is better then something  that 
looks like the perl DeCSS program.  If you need the nano seconds that
much buy a better box !.

Mark

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


Re: [PHP] PHP and XML.

2004-02-02 Thread Mark Ackroyd


Rolf Brusletto wrote:

The only thing I can think of is apache/you_webserver_here is limiting 
the amount of memory.. still an odd problem though, depending on the 
size of the xml..
The XML is tiny, 12 lines.  I got round the problem by chopping up 
someone elses PHP XML parser script, so that it wasn`t using expat.

Wich I had time to look into all of these little things :-)

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


[PHP] PHP and XML.

2004-01-30 Thread Mark Ackroyd
Odd problem.

I have written a small script that processes some XML, it runs on a few 
FreeBSD boxes I admin over. On one of the boxes (the only one) .. if I 
run this script through apache, The xml_set_element_handler and 
xml_set_character_data_handler functions return a 1 error (out of memory)

If I run the scripts from the Command lime they work fine !

anyone got any ideas?

Mark

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


[PHP] PHP and Java

2003-12-11 Thread Mark Ackroyd
Hi,

I am not so sure where the problem lies with this. I have installed 
JDK1.3.1 on a FreeBSD 4.9 server. It seems to work fine. I have written 
a small java program and it compiles and runs without any issues.

I want to get the PHP intgration with java working, I must admit I know 
more about compiling and tinkering with PHP source then java. So I have 
set all the right options in PHP for this intergration and got the thing 
to compile.

in my small PHP script to test the system is this.

#!/usr/local/bin/php -q
?
  $system_inst = new Java('java.lang.System');
  echo $system_inst-getProperty(java.version);
?
when this is run it produces this.

PHP Fatal error:  Unable to load Java Library 
/usr/local/jdk1.3.1/jre/lib/i386/classic/libjvm.so, error: 
/usr/local/jdk1.3.1/jre/lib/i386/classic/libjvm.so: Undefined symbol 
setFPMode in /root/test on line 3

I know the setFPmode is due to the threads in java so I have set

LD_LIBRARY_PATH=/usr/local/jdk1.3.1/jre/lib/i386/green_threads

Either way this problem doesn`t seem to go away with the LD references?

anyone got an ideas of what I am doing wrong?

Mark

--

Mark Ackroyd
e: [EMAIL PROTECTED]
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php