RE: [PHP] PHP Command line script

2007-05-02 Thread Peter Lauri
Check the error from mysqli:

http://fi.php.net/manual/en/function.mysqli-error.php

Best regards,
Peter Lauri

www.dwsasia.com - company web site
www.lauri.se - personal web site
www.carbonfree.org.uk - become Carbon Free

 -Original Message-
 From: Nathaniel Hall [mailto:[EMAIL PROTECTED]
 Sent: Tuesday, May 01, 2007 10:13 PM
 To: php-general@lists.php.net
 Subject: [PHP] PHP Command line script
 
 I am attempting to run a script that will run from the command line
 nightly to update a field in a database.  I already created a script
 that would access the database and insert most of the information when a
 webpage is visited and I had no problems with it.  The command line
 script appears to fail on the prepare.  I have echo'ed the SQL statement
 to the screen, copied it, and run it on the MySQL server with no
 problems.  Any ideas?
 
 ?php
 $mysqli = new mysqli('localhost', 'root', 'abc123', 'mydb');
 if (mysqli_connect_errno()) {
 echo Unable to connect to database.\n;
 exit;
 } else {
 $login = date('m\-d\-Y');
 if ($logout = $mysqli-prepare(UPDATE `mydb`.`authlog`
 SET `logout`  = ? WHERE `login` LIKE '$login%')) { // --- Will not go
 any further than here, even when hard coding the information.
 $logout-bind_param(s, date('m\-d\-
 Y\TH\:i\:s'));
 $logout-execute();
 $logout-close();
 }
 }
 $mysqli-close();
 ?
 
 --
 Nathaniel Hall, GSEC GCFW GCIA GCIH GCFA
 Spider Security
 
 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php

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



Re: [PHP] PHP Command line script

2007-05-02 Thread Nathaniel Hall

Greg Donald wrote:


On 5/1/07, Nathaniel Hall [EMAIL PROTECTED] wrote:
 I am attempting to run a script that will run from the command line
 nightly to update a field in a database.  I already created a script
 that would access the database and insert most of the information when a
 webpage is visited and I had no problems with it.  The command line
 script appears to fail on the prepare.  I have echo'ed the SQL statement
 to the screen, copied it, and run it on the MySQL server with no
 problems.  Any ideas?

 ?php
 $mysqli = new mysqli('localhost', 'root', 'abc123', 'mydb');
 if (mysqli_connect_errno()) {
 echo Unable to connect to database.\n;
 exit;
 } else {
 $login = date('m\-d\-Y');
 if ($logout = $mysqli-prepare(UPDATE `mydb`.`authlog`
 SET `logout`  = ? WHERE `login` LIKE '$login%')) { // --- Will not go
 any further than here, even when hard coding the information.
 $logout-bind_param(s, 
date('m\-d\-Y\TH\:i\:s'));

 $logout-execute();
 $logout-close();
 }
 }
 $mysqli-close();
 ?


Add full error reporting, then make sure you can see the errors, then
test to see if you have the mysqli extension:

error_reporting( E_ALL );
ini_set( 'display_errors', 1 );
ini_set( 'log_errors', 1 );

if( !in_array( 'mysqli', get_loaded_extensions() ) )
{
die( 'no mysqli found' );
}


I get no errors and I have verified that mysqli is loaded.


Also, why do you need to escape the dashes in the date() calls?

 php -r 'echo date(Y-m-d);'
2007-05-01


Habit.

--
Nathaniel Hall, GSEC GCFW GCIA GCIH GCFA
Spider Security

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



Re: [PHP] PHP Command line script

2007-05-02 Thread Richard Lynch
On Tue, May 1, 2007 3:13 pm, Nathaniel Hall wrote:
 ?php
 $mysqli = new mysqli('localhost', 'root', 'abc123', 'mydb');
 if (mysqli_connect_errno()) {
 echo Unable to connect to database.\n;
 exit;
 } else {
 $login = date('m\-d\-Y');
 if ($logout = $mysqli-prepare(UPDATE
 `mydb`.`authlog`
 SET `logout`  = ? WHERE `login` LIKE '$login%')) { // --- Will not
 go
 any further than here, even when hard coding the information.
 $logout-bind_param(s,
 date('m\-d\-Y\TH\:i\:s'));
 $logout-execute();
 $logout-close();
 }

//ALWAYS do your error-checking!!!
  else{
die(mysqli_error());
  }

//You may want to put the query in $query so you can print that
//as part of the 'die' output

 }
 $mysqli-close();
 ?

-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

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



[PHP] PHP Command line script

2007-05-01 Thread Nathaniel Hall
I am attempting to run a script that will run from the command line 
nightly to update a field in a database.  I already created a script 
that would access the database and insert most of the information when a 
webpage is visited and I had no problems with it.  The command line 
script appears to fail on the prepare.  I have echo'ed the SQL statement 
to the screen, copied it, and run it on the MySQL server with no 
problems.  Any ideas?


?php
   $mysqli = new mysqli('localhost', 'root', 'abc123', 'mydb');
   if (mysqli_connect_errno()) {
   echo Unable to connect to database.\n;
   exit;
   } else {
   $login = date('m\-d\-Y');
   if ($logout = $mysqli-prepare(UPDATE `mydb`.`authlog` 
SET `logout`  = ? WHERE `login` LIKE '$login%')) { // --- Will not go 
any further than here, even when hard coding the information.

   $logout-bind_param(s, date('m\-d\-Y\TH\:i\:s'));
   $logout-execute();
   $logout-close();
   }
   }
   $mysqli-close();
?

--
Nathaniel Hall, GSEC GCFW GCIA GCIH GCFA
Spider Security

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



Re: [PHP] PHP Command line script

2007-05-01 Thread Daniel Brown

   First and foremost, it's a VERY BAD idea to use root for MySQL.  If your
code isn't perfect (and even sometimes if it is), arbitrary commands and SQL
injection attacks could lead to migraines that no Tylenol will ever be able
to alleviate.

   Secondly, what error is the CLI kicking out when you run it from the
command line?

On 5/1/07, Nathaniel Hall [EMAIL PROTECTED] wrote:


I am attempting to run a script that will run from the command line
nightly to update a field in a database.  I already created a script
that would access the database and insert most of the information when a
webpage is visited and I had no problems with it.  The command line
script appears to fail on the prepare.  I have echo'ed the SQL statement
to the screen, copied it, and run it on the MySQL server with no
problems.  Any ideas?

?php
$mysqli = new mysqli('localhost', 'root', 'abc123', 'mydb');
if (mysqli_connect_errno()) {
echo Unable to connect to database.\n;
exit;
} else {
$login = date('m\-d\-Y');
if ($logout = $mysqli-prepare(UPDATE `mydb`.`authlog`
SET `logout`  = ? WHERE `login` LIKE '$login%')) { // --- Will not go
any further than here, even when hard coding the information.
$logout-bind_param(s,
date('m\-d\-Y\TH\:i\:s'));
$logout-execute();
$logout-close();
}
}
$mysqli-close();
?

--
Nathaniel Hall, GSEC GCFW GCIA GCIH GCFA
Spider Security

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





--
Daniel P. Brown
[office] (570-) 587-7080 Ext. 272
[mobile] (570-) 766-8107


Re: [PHP] PHP Command line script

2007-05-01 Thread Nathaniel Hall

Daniel Brown wrote:


First and foremost, it's a VERY BAD idea to use root for MySQL.  
If your code isn't perfect (and even sometimes if it is), arbitrary 
commands and SQL injection attacks could lead to migraines that no 
Tylenol will ever be able to alleviate.
I changed the user I was connecting as in order to post.  I don't use 
root in the real code.


Secondly, what error is the CLI kicking out when you run it from 
the command line?
It doesn't give an error.  The only thing it does is continue on through 
the IF statement, which goes nowhere.  I have added an ELSE to the 
script and run it.  It ends up running the code in the ELSE.



$login = date('m\-d\-Y');
if ($logout = $mysqli-prepare(UPDATE `mydb`.`authlog` SET
`logout`  = ? WHERE `login` LIKE '$login%')) { // --- Will not
go any further than here, even when hard coding the information.
  $logout-bind_param(s, date('m\-d\-Y\TH\:i\:s'));
  $logout-execute();
  $logout-close();
}


--
Nathaniel Hall, GSEC GCFW GCIA GCIH GCFA
Spider Security

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



Re: [PHP] PHP Command line script

2007-05-01 Thread Greg Donald

On 5/1/07, Nathaniel Hall [EMAIL PROTECTED] wrote:

I am attempting to run a script that will run from the command line
nightly to update a field in a database.  I already created a script
that would access the database and insert most of the information when a
webpage is visited and I had no problems with it.  The command line
script appears to fail on the prepare.  I have echo'ed the SQL statement
to the screen, copied it, and run it on the MySQL server with no
problems.  Any ideas?

?php
$mysqli = new mysqli('localhost', 'root', 'abc123', 'mydb');
if (mysqli_connect_errno()) {
echo Unable to connect to database.\n;
exit;
} else {
$login = date('m\-d\-Y');
if ($logout = $mysqli-prepare(UPDATE `mydb`.`authlog`
SET `logout`  = ? WHERE `login` LIKE '$login%')) { // --- Will not go
any further than here, even when hard coding the information.
$logout-bind_param(s, date('m\-d\-Y\TH\:i\:s'));
$logout-execute();
$logout-close();
}
}
$mysqli-close();
?



Add full error reporting, then make sure you can see the errors, then
test to see if you have the mysqli extension:

error_reporting( E_ALL );
ini_set( 'display_errors', 1 );
ini_set( 'log_errors', 1 );

if( !in_array( 'mysqli', get_loaded_extensions() ) )
{
   die( 'no mysqli found' );
}

Also, why do you need to escape the dashes in the date() calls?


php -r 'echo date(Y-m-d);'

2007-05-01



--
Greg Donald
http://destiney.com/

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



Re: [PHP] PHP Command Line Scripts 'Aborting' at end ...

2004-10-28 Thread Curt Zirzow
* Thus wrote Marc G. Fournier:
 
 Note that the following is based on php installed via the FreeBSD ports 
 system ...
 
 
 
 I'm getting a core file, but if I try:
 
 gdb /usr/local/bin/php php.core ... its definitely not looking good:
 
 s# gdb /usr/local/bin/php php.core
 ...
 
 Core was generated by `php'.
 Program terminated with signal 6, Abort trap.
 Reading symbols from /usr/lib/libcrypt.so.2...done.
 Reading symbols from /usr/lib/libm.so.2...done.
 Reading symbols from /usr/lib/libc.so.4...done.
 Reading symbols from /usr/local/lib/php/20020429/interbase.so...done.
 Reading symbols from /usr/local/firebird/lib/libfbembed.so.1...Deprecated 
 bfd_read called at 
 /usr/src/gnu/usr.bin/binutils/gdb/../../../../contrib/gdb/gdb/dwarf2read.c 
 line 3049 in dwarf2_read_section
 Error while reading shared library symbols:
 Dwarf Error: Cannot handle DW_FORM_strp in DWARF reader.
 Reading symbols from /usr/lib/libncurses.so.5...done.
 Error while reading shared library symbols:
 ì: No such file or directory.
 Error while reading shared library symbols:
 ynamic: No such file or directory.
 Segmentation fault (core dumped)

Interesting core dump :)

Try running php directly from gdb instead of reading the core file:
  % gdb /usr/loca/bin/php
  ...
   run script.php
  ...
   bt
 
See if that produces a better backtrace.


 
 mod_php4 appears to work fine, just the command line version seems to be 
 off ... and its running, producing expected output, its just that last 
 'Abort' that tends to screw things up a bit ...

My bet is you have a buggy library somewhere, ncurses being a
viable candidate since it does not get loaded in  mod_php4.


Curt
-- 
Quoth the Raven, Nevermore.

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



[PHP] PHP Command Line Scripts 'Aborting' at end ...

2004-10-27 Thread Marc G. Fournier
Note that the following is based on php installed via the FreeBSD ports 
system ...

I have a really simple PHP script that, when you run it, generates an 
Abort at the end of it:

ams# /tmp/test.php
testAbort (core dumped)
ams# cat /tmp/test.php
#!/usr/local/bin/php
?php
echo test;
?
Even if I change the script slightly, so that last line isn't being run 
via php, it does the same:

ams# cat /tmp/test.php
#!/usr/local/bin/php
?php
echo test;
?
test
ams# /tmp/test.php
test
test
Abort (core dumped)
I'm getting a core file, but if I try:
gdb /usr/local/bin/php php.core ... its definitely not looking good:
s# gdb /usr/local/bin/php php.core
GNU gdb 4.18 (FreeBSD)
Copyright 1998 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type show copying to see the conditions.
There is absolutely no warranty for GDB.  Type show warranty for details.
This GDB was configured as i386-unknown-freebsd...Deprecated bfd_read called at 
/usr/src/gnu/usr.bin/binutils/gdb/../../../../contrib/gdb/gdb/dbxread.c line 2627 in 
elfstab_build_psymtabs
Deprecated bfd_read called at 
/usr/src/gnu/usr.bin/binutils/gdb/../../../../contrib/gdb/gdb/dbxread.c line 933 in 
fill_symbuf
Core was generated by `php'.
Program terminated with signal 6, Abort trap.
Reading symbols from /usr/lib/libcrypt.so.2...done.
Reading symbols from /usr/lib/libm.so.2...done.
Reading symbols from /usr/lib/libc.so.4...done.
Reading symbols from /usr/local/lib/php/20020429/interbase.so...done.
Reading symbols from /usr/local/firebird/lib/libfbembed.so.1...Deprecated bfd_read 
called at /usr/src/gnu/usr.bin/binutils/gdb/../../../../contrib/gdb/gdb/dwarf2read.c 
line 3049 in dwarf2_read_section
Error while reading shared library symbols:
Dwarf Error: Cannot handle DW_FORM_strp in DWARF reader.
Reading symbols from /usr/lib/libncurses.so.5...done.
Error while reading shared library symbols:
ì: No such file or directory.
Error while reading shared library symbols:
ynamic: No such file or directory.
Segmentation fault (core dumped)
mod_php4 appears to work fine, just the command line version seems to be 
off ... and its running, producing expected output, its just that last 
'Abort' that tends to screw things up a bit ...

Not sure how to debug ... help?
Thanks ...

Marc G. Fournier   Hub.Org Networking Services (http://www.hub.org)
Email: [EMAIL PROTECTED]   Yahoo!: yscrappy  ICQ: 7615664
-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: [PHP] PHP Command Line Scripts 'Aborting' at end ...

2004-10-27 Thread Greg Donald
On Wed, 27 Oct 2004 13:44:54 -0300 (ADT), Marc G. Fournier
[EMAIL PROTECTED] wrote:
 
 Not sure how to debug ... help?

You said you installed in via ports, so did you happen to check the
'debug' option when you installed it?

[ ] DEBUG Enable debug

Just a question.. as that might help explain more what's going on.


-- 
Greg Donald
Zend Certified Engineer
http://gdconsultants.com/
http://destiney.com/

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



Re: [PHP] PHP Command Line Scripts 'Aborting' at end ...

2004-10-27 Thread Greg Donald
On Wed, 27 Oct 2004 13:44:54 -0300 (ADT), Marc G. Fournier
[EMAIL PROTECTED] wrote:
 
 I have a really simple PHP script that, when you run it, generates an
 Abort at the end of it:
 
 ams# /tmp/test.php
 testAbort (core dumped)

I just installed php4-cgi on a FreeBSD 4.10 system I have.  The same
test.php script runs fine for me.

 cat test.php
#!/usr/local/bin/php
?php
echo test;
?

 ./test.php
Content-type: text/html
X-Powered-By: PHP/4.3.9

test


-- 
Greg Donald
Zend Certified Engineer
http://gdconsultants.com/
http://destiney.com/

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



Re: [PHP] PHP Command Line Scripts 'Aborting' at end ...

2004-10-27 Thread Marc G. Fournier
I just did a reinstall from ports, and it works now as well ... maybe a 
stale library for one of hte modules :(

thanks ...
On Wed, 27 Oct 2004, Greg Donald wrote:
On Wed, 27 Oct 2004 13:44:54 -0300 (ADT), Marc G. Fournier
[EMAIL PROTECTED] wrote:
I have a really simple PHP script that, when you run it, generates an
Abort at the end of it:
ams# /tmp/test.php
testAbort (core dumped)
I just installed php4-cgi on a FreeBSD 4.10 system I have.  The same
test.php script runs fine for me.
cat test.php
#!/usr/local/bin/php
?php
   echo test;
?
./test.php
Content-type: text/html
X-Powered-By: PHP/4.3.9
test
--
Greg Donald
Zend Certified Engineer
http://gdconsultants.com/
http://destiney.com/
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Marc G. Fournier   Hub.Org Networking Services (http://www.hub.org)
Email: [EMAIL PROTECTED]   Yahoo!: yscrappy  ICQ: 7615664
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] PHP command line vars

2003-11-18 Thread Shawn McKenzie
I have a script that I want to run on the windows command line, and it is
working fine.  What I want to do is pass vars to the script when I run it,
example:  php script.php $var=hello

I have read the docs but can't find the syntax to pass these in.  Also, how
to retrieve them in the script?  argv other?

TIA
-Shawn

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



Re: [PHP] PHP command line vars

2003-11-18 Thread Marek Kilimajer
Shawn McKenzie wrote:

I have a script that I want to run on the windows command line, and it is
working fine.  What I want to do is pass vars to the script when I run it,
example:  php script.php $var=hello
The example will not work, command line arguments are traditionaly 
passed in the form of:
php script.php --long-name hello
or
php script.php -n hello

You will have to parse $argv array to get the command line arguments.

I have read the docs but can't find the syntax to pass these in.  Also, how
to retrieve them in the script?  argv other?
http://www.php.net/manual/en/features.commandline.php

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


Re: [PHP] PHP command line vars

2003-11-18 Thread Shawn McKenzie
Thanks!  The link was just what I needed.

-Shawn

Marek Kilimajer [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 Shawn McKenzie wrote:

  I have a script that I want to run on the windows command line, and it
is
  working fine.  What I want to do is pass vars to the script when I run
it,
  example:  php script.php $var=hello
 The example will not work, command line arguments are traditionaly
 passed in the form of:
 php script.php --long-name hello
 or
 php script.php -n hello

 You will have to parse $argv array to get the command line arguments.

 
  I have read the docs but can't find the syntax to pass these in.  Also,
how
  to retrieve them in the script?  argv other?

 http://www.php.net/manual/en/features.commandline.php

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



[PHP] php command line

2002-04-30 Thread Ezra Nugroho

I was trying to compile php command line and got some problem.
Maybe some of you can help.

version: 4.1.2
I did:
./configure --with-ldap --with-oracle --with-oci8 
--with-mysql=/usr/src/mysql-3.23.43-pc-linux-gnu-i686 --enable-track-vars 
--disable-debug --prefix=/usr/local/apache/php 
--with-config-file-path=/usr/local/apache/lib --with-gd

when tested, it gave:
Failed loading /usr/local/apache/libexec/ZendOptimizer.so: 
/usr/local/apache/libexec/ZendOptimizer.so: cannot open shared object file: 
No such file or directory

I couldn't find ZendOptimizer.so anywhere.
Any clue?

Thanks,






Ezra Nugroho
Web/Database Application Specialist
Goshen College Information Technology Services
Phone: (574) 535-7706



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




[PHP] PHP command line scripting multiple process forking

2002-03-21 Thread Walker, Roy

I have been playing with this for a couple of days and have run into a few
issues:

I am wanting to run a set number of multiple processes (ie 25 at a time).  I
can't use the exec command since it will not wait for the output (this is a
delayed response - network based).

$cmd = /path.to/some.cmd;
$options = --options;

$lines = file (/path.to/some.file);
while (list ($line_num, $line) = each ($lines)) {
$trimline = trim ($line);
shell_exec ($cmd $options $trimline );
}

This works but I want to fork it multiple times and have a set number of
lines running at a time.  Anyone have any ideas?

Thank you,
Roy Walker

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