Re: [PHP-DB] Functions

2004-02-02 Thread Jochem Maas
elaborating (?spelling) on Micahs loop:

funcs.php:
?
function sanitize($glob = null)
{
if (is_null($glob) || !is_array($$glob)) {
// set name of the global var we care about
// if no valid name was passed to the function
$glob = '_REQUEST';
}
// using a variable variable name: $$glob now refers to $_REQUEST
// assuming no arguments were passed to the function.
// doing this allows sanitizing just $_POST, $_GET or $_COOKIE
// in case
foreach ($$glob as $key = $value) {
// sanitize all incomings
$$glob[$key] = $santizedValue;
}
}
function validate($value, $type)
{
$isValid = false;
switch ($type) {
case 'email':
// if email is OK do $isValid = true;
break;
case 'address':
// check address
break;
default:
   // the fallback plan.
   // e.g.
   if (!empty($value)) {
   $isValid = true;
   }
   break;
}
return $isValid;
}
?
--endof funcs.php
test.php
?
require_once ('./funcs.php');

// clean and make safe our incoming values
sanitize('_POST');
$validationFields = array(
'myname'  = 'name',
'myemail' = 'email',
'myaddr'  = 'address',
);
// check to see if something was submitted
if(is_array($_POST)  count($_POST)) {
define('FORM_SUBMITTED', 1);
}
foreach($validationFields as $field = $type) {
// possibly we want to valid
if (defined('FORM_SUBMITTED')) {
// a form was posted...
if(!validate($_POST[ $field ], $type)) {
define('ERROR', 1);
break; // stop the loop
}
$$field = $_POST[ $field ];
} else {
$$field = '';
}   
}
if (defined('FORM_SUBMITTED')) {
if (!defined('ERROR')) {
// stick the data in a database or email them...
define('MSG', 'your data was excellently constructed!');
} else {
   // something bad happened
   define('MSG', 'something bad happened please check your data');
}
} else {
// something bad happened
define('MSG', 'welcome, please fill in this form');
}
?
html
body
h1My Form/h1
?=MSG;?
form method=post action=?=$_SERVER['PHPSELF'];?
*name: input name=myemail value=?=$myname;?/br /
*email: input name=myemail value=?=$myemail;?/br /
*address: input name=myemail value=?=$myaddr;?/br /
input type=submit value=submit /
/form
/body
/html
--endof test.php

Micah Stevens wrote:

Chis,

I think this might do what you want:

foreach ($_REQUEST as $key = $value) {
	switch ($key) {
		case email:
			// do email stuff
			break;
		case address:
			// do address stuff
			break;
		default:
			// in case it's something you haven't planned for.. 
			break;
	}
}
	
		

On Mon February 2 2004 4:36 pm, Chris Payne wrote:

Hi there everyone,

I need to write a function (New to them but starting to get the hang of it)
that will take the field from a form and then do operations on it (To
remove bad characters, any entered mysql commands etc ) now that's not
a problem, what I want to do though is write a generic function that will
handle ALL the fields in any form.
For example, if I have 3 input boxes, name, address, email - I would like
the function to recieve the data from each form string and do the operation
and then send the info back keeping the same name and value that it arrived
in.  I'm finding it hard to explain, but basically if a field is called
email and it's value is [EMAIL PROTECTED] then the function needs to be able to
automatically pickup that the incoming name is email and it's value it
[EMAIL PROTECTED] then process it and output it again, and i'm confused how to do
it.
I can do it if I specify the name of the form item coming in and going out,
but since I want to make it generic I don't want a zillion different
possible form names in the function :-)
Any help (If you can understand my rambling :-) would be greatly
appreciated.
Regards

Chris


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


Re: [PHP-DB] Forum Script

2004-03-07 Thread Jochem Maas
Marcjon Louwersheimer wrote:

Hello friends.

I am currently trying to develop a forum system. All is going well, but I
was wondering if there woud be a way to do something that I'm already
doing that might be more efficient. 
..

it might be worthwhile having a looking at and playing with the code of 
one of the many PHP based forum systems. many of the problems you 
have/will come accross will probably have been solved in some way 
already (whether its a good solution is upto you to decide!)

..
Currently while it's doing the WHILE loop, it performs another query for
each post, checking how many posts have there reply field set to the
post's current ID
a simple way would be to make one extra SQL call (in addition to the one 
for the post details) which does a count for every distinct reply_id

SELECT reply_id, COUNT(*) AS cnt FROM topic_table

and use this result for the count info instead of making a DB call for 
every row in the original resultset. you could load an array with the 
count data ala (this would be done with a loop over the mysql result):

$countData = array();
$countData[ $row['reply_id'] ] = $row['cnt'];
.. etc
and then when you loop over the actual topic data
you can get the count for the current topid by doing the following:
echo $countData[ $currentTopicId ];

-- my SQL maybe incorrect

Or maybe there's a more effective
way by getting the number of replies first. I don't really want to store
the number of replies in the database, if I can.
If I'm not being clear or I'm not using proper netiquette, I appologize,
I'm new to this (mailing lists). Any help would be appreciated!
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] problem Connecting

2004-03-07 Thread Jochem Maas
Will wrote:

Hello all,
When I try to connect I get this message: #1045 - Access denied for 
user: [EMAIL PROTECTED]' (Using password: YES).

Can anyone help me?  Do I need to do anything in the php.ini file or 
anywhere else.
sounds like you need to set a password in the phpMyAdmin config file for 
the root user (as defined in MYSQL) because obviously logging in with an 
empty password doesn't work.

I am trying to get phpMyAdmin to login into the database.

~WILL~

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


Re: [PHP-DB] Impact of MySQL Queries

2004-03-12 Thread Jochem Maas
Marcjon, I think you have asked this question before. there are replies 
to it, have you checked those?

Marcjon Louwersheimer wrote:

I'm working on a forum. When
it displays a forum index, it gets all the topics and depending on the
offset, displays only ten at a time. Now that's a single query. But
problem comes when I display how many replies each post has. So far, when
it does the while loop, it does a query for each item. Here's the code:
...

while ($row = mysql_fetch_assoc($indexresult)) // Run through all the posts
{   
$while_offset++;
if ($while_offset  $offset AND $while_count = 10){ // if the 
post is in the range
$while_count++;
this would mean you fetch the whole result (not just 10 lines) and loop 
over all of it.

it would be much better to make use of the mySQL syntax:

[LIMIT [offset,] row_count | row_count OFFSET offset]

see: http://www.mysql.com/doc/en/SELECT.html

free advice: take the time to read manuals even if your not stuck on a 
particular problem, you often come across solutions to problems you 
haven't encountered yet! if you're serious about PHP and mySQL then 
reading both manuals back2front will save you time in the long run + 
open your eyes to a whole lot of stuff - if you don't understand 
something, skip it and move on - something you read later will probably
help to explain it.

...

Is there an easier way to do this, maybe with a sub select statement
yes.

maybe? I only know basic mysql. I hope this is understandable...
subselects are available in mySQL 4 I believe (don't hold me to it)...
my current DB preference goes to Firebird 1.5
Oh yeah, you might wonder why I use the custom offset instead of using
the LIMIT and OFFSET clauses in the main MySQL query. The problem with
this is
that when I order the posts, it would only order them by the one gotten,
not them all, which is what I wanted. 
which is the same thing, assuming you are using the same ORDER BY 
clause. ok, so in one case the result set doesn't contain certain rows 
but these are the rows that you wouldn't show anyway.

your original question about minimizing the number of SQL queries is 
answered in the reply(s?) to one of your other posts.
subject= Re: [PHP-DB] Forum Script
date   = 3/7/2004 9:23 PM (god knows how accurate that is)

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


Re: [PHP-DB] Trying to reduce the number of queries

2004-04-08 Thread Jochem Maas
using grouping:

SELECT count(application.*), application.media_ID, mailbox.company_ID
FROM application, mailbox
WHERE mailbox.app_ID = application.ID
GROUPBY mailbox.company_ID, application.media_ID
SQL is unchecked;

try to look at the problem from the other direction
determine what information you want to extract the dive into
the mySQL manual to determine if there is any SQL syntax that
provides the data inherent in the database in the form you want it.
with regard to speed - oh boy it will!

they way I see it, in an 'information age' data is king - which means 
the database, being the closest to the king, should pre-process as much 
as possible - only do it is as little queries as poss. because each trip 
 to the data base is overhead:

n - num of rows
T - time for 1 good query
t - time for 1 bad query
O - connection overhead
single query| many queries
O+T | n*t + n*O
seeing as databases are optimized to perform the kind of action you 
require you can expect the saving to be considerable in technical terms 
- in real life you may see little change, none the less you know that 
you script is more effecient and can therefore handle a higher load.

notice the layout of the SQL;

$sql = '
SELECT count(application.*), application.media_ID, mailbox.company_ID
FROM application, mailbox
WHERE mailbox.app_ID = application.ID
GROUPBY mailbox.company_ID, application.media_ID';
little things like this help when you _have_ to go in and optimize the 
code a year after you last touched it.

if its your first app, you probably see no end to, after a few you begin 
to realise that they're all just one every evolving/mutating collection 
of code to which there is no end. the moral of the story trust your 
instincts. :-)

Ryan Marks wrote:

Hello all,

My script works fine as it is, but I am trying to reduce the number of
queries to the database.  I am running PHP 4.3.4 and MySQL 4.0.3.
Here is my table structure:
...

TIA,
Ryan Marks
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] stumped-mail and database

2004-12-06 Thread Jochem Maas
er, I don't know if it would interest you but here is a class I have 
been using for ages now (not that I have trouble using mail() for simple 
jobs) because its simple, packed with functionality and works well:

http://phpmailer.sourceforge.net/
the following page hopefully demonstrates how simple it is to setup/use:
http://phpmailer.sourceforge.net/extending.html
Norland, Martin wrote:
-Original Message-
...
1) change
$to = $rsVendorJobs-Fields('Conmail');
I suspect that $to would contain something like:
(Object) -Fields('Conmail')
or something even more garbage like (i.e. ),
'complex' $variables in doubled quotes strings should always
be wrapped in curly braces, if only for clarities sake
(if you want to know exactly when they are required then RTFM ;-).
To
$to = {$rsVendorJobs-Fields('Conmail')};
Or just
$to = $rsVendorJobs-Fields('Conmail');
this is the best way - saves some string interpolation.
2) change 
$body = '$cl';
	To
$body = $cl;

3) from mail() docs
[this is just for reference, since you're only sending one header it's
probably not a problem]
Note:  You must use \r\n to separate headers, although some Unix mail
transfer agents may work with just a single newline (\n).
Then we'll see where you are from there...
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] stumped-mail and database

2004-12-06 Thread Jochem Maas
Stuart Felenstein wrote:
--- Norland, Martin [EMAIL PROTECTED]
wrote:

All I can recommend from here is heavy use of
printr() or var_dump() on
your variables.
They are NULL.  That is the problem.  I can't for the
life of me , figure out a way to initialize these
variables.
be more specific - its not at all clear which variables are null?
is your 'recordset' ($rsVendorJobs) actually an object?
if not you have to go into the $-SelectLimit($query_rsVendorJobs) 
call to find out what is going wrong.

Is this the first time you are attempting to use the DB abstraction
objects/classes that your code snippets hint at? if so,
specify exactly what it is, it may help.
also have you checked your error logs?
 

Obviously, also, you'll want to print out the query
you're using to make
sure it's actually correct sql/being populated/etc. 
Perhaps even run a
var_dump($-SelectLimit($query_rsVendorJobs)) to
see just what
result you're getting back, although from your code
it should exactly
match a dump of $rsVendorJobs.

Yeah , the sql is cool  Everything returns as
expected.
Stuart
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] stumped-mail and database

2004-12-06 Thread Jochem Maas
I just thought, if your query object ($) is returning a
resultset object then maybe you have to 'loop' the resultset object
in order to retrieve the 'row' object(s) from which you can retrieve the 
data.

your resultset object doesn't have a GetRowAssoc() method?
[ defined as GetRowAssoc($upper=true) ]
Norland, Martin wrote:
var_dump($rsVendorJobs);
object(kt_adorecordset_mysql)(33) { [dataProvider]=

Looks like you're using the ADODB library (
http://www.certicamara.com/consulta/lib/adodb/docs-adodb.htm ) or
similar.  ( That may not be the official site, I just bounced around a
bit. )
All your previous code looks to have been correct, so I'm not really
sure where to go from here.  You may want to look into $ADODB_FETCH_MODE
and see if you can't just get an associative array with your fields
directly out, instead of pulling each little piece out through the
convenience function Fields() (which... doesn't seem to be working).
Not best practice - in fact, extremely BAD practice, but you should be
able to access it with $rsVendorJobs-fields['fieldname'].  Note, of
course, that that's internal structure of their object - and you should
NOT be directly accessing such things.  Still, it will help you check if
you're sane.
I really REALLY don't recommend directly digging into a black box like
this unless you know it will never change, or have some good
documentation area where people will know to look before upgrading.
- Martin Norland, Database / Web Developer, International Outreach x3257
The opinion(s) contained within this email do not necessarily represent
those of St. Jude Children's Research Hospital.

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


Re: [PHP-DB] sessions

2004-12-09 Thread Jochem Maas
try using the $_SESSION superglobal var (google is your friend if its 
new to you.)

no need to register (still need to do session_start() though) just do...
$_SESSION['MyValue'] = array(
'name'  = $username,
'level' = $account_level
);
...or something like that. (also works for objects - which is only gets 
really cool in php5 - be aware that classes for objects stored in your 
session should be loaded BEFORE you start the session.)

Warren Mason wrote:
I am attempting to get information from a mysql database and then use
this in a session. Is there a trick to using sessions? For example, can
something like below be placed anywhere in a script? (I have the 
session_start(); at the very top of my page.)  


  session_register( session_username ); 
  session_register( session_level );  
 
 $session_username = $username;
 $session_level = $account_level; 

The resulting session is
session_username|N;session_level|i:0;
$username is set to warren and $account_level is set to 255.
Any help would be greatly appreciated as I have gone through about 5
books and searched the net and can't find an answer as to why this isn't
working.
-
This message is intended for the addressee named and may contain
confidential information. If you are not the intended recipient, please
delete it and notify the sender. Views expressed in this message are
those of the individual sender and are not necessarily the views of the
Mid Western Area Health Service.
-
gwavasig
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] String question

2004-12-14 Thread Jochem Maas
Chris Payne wrote:
Hi there everyone,
 

I am having to read a string with text in, but the way the DB is written in
the same string you have the price, for example
this doesn't sound like a DB problem, sounds more like a regexp problem.
(i.e. php-db is probably the wrong list)
 

CASARON 4G
50lb Sacks in Ton Lots
$88.00
 

How can I strip out the 88.00 (Baring in mind it could be any number)  into
its own string?
http://nl2.php.net/manual/en/ref.pcre.php
NB: note the difference between using single and double quotes when
defining your regexp. e.g:
$regexp = '/^.*\$[ \t]?([0-9]+\.[0-9]{2})$/s';
and:
$regexp = /^.*\$[ \t]?([0-9]+\.[0-9]{2})$/s;
...are not the same.
assuming that the price is at the end of the string you and is preceeded 
by a dollar sign (with or without a seperating space) could do:

?php
$myString = 
CASARON 4G
50lb Sacks in Ton Lots
$88.00
\r\n
\t\r\n
;
$matches = array();
$found = preg_match(
   '/^.*\$[ \t]?([0-9]+\.[0-9]{2})$/s',
   /* some commented out alternatives */
   // '/^.*\$([0-9]+\.[0-9]{2})$/s',
   // '/^.*\$([0-9]+\.00)$/s',
   // '/^.*\$(88\.00)$/s',
   // '/.*\$(\d+\.\d+)/s',
   trim($myString), /* make life easier have a trim */
   $matches /* passed by ref */
   );
print_r(original string:\n--\n$myString);
print_r(\n\ntrimmed string:\n--\n.trim($myString).\n\n);
print_r(found: $found\n matches array contents:\n\n);
print_r($matches);
?
 

Thank you.
 

Chris
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.816 / Virus Database: 554 - Release Date: 12/14/2004
 

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


Re: [PHP-DB] characters problem

2004-12-17 Thread Jochem Maas
Bastien Koert wrote:
Two years and you haven't heard of:
addslashes?
mysql_reaL_escape_string?
or even something as simple as
$comments = str_replace(','',$comments);
to replace the one quote with two single quotes (don't forget to remove 
them on the display...)
I thount that the first single-quote escapes the second and only 1 is 
stored. so I took 2 seconds to type 'mysql.com single quote' into 
google and ...

well check out: http://dev.mysql.com/doc/mysql/en/String_syntax.html
(personally I think the style  CS on the site makes some of the 
information hard to digest)

good luck.

bastien
From: Panos Yahoo [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Subject: [PHP-DB] characters problem
Date: Fri, 17 Dec 2004 09:38:15 +0200
Dear All,
I am using php and mysql the last two years, and I still cannot find 
the way
to update a field on mysql from php that containts the single quotes ( 
` and
' )

Examples
Here is an example of my index.php file. I have to type something on
Comments field
- 

?
include(../configs/dates.inc);
include(../configs/config.inc);
echo 
br
body bgcolor=#FFF8E1 text=#2003CF link=#2003CF vlink=#2003CF 
alink=#2003CF
center
form method=post action=add.php

font face=\Comic Sans MS\Commentsbrtextarea rows=3 cols=40
name=mycomments tabind
ex=22/textarea
input type=submit name=Submit value=\Add Ticket\
input type=reset name=Reset value=\Clear Form\
;
mysql_close($myconn);
?
- 



In the html text area, I am typing the following text : Hello My name is
Panos and I'm from Greece

The add.php file looks like this :
- 

?
include(../configs/dates.inc);
include(../configs/config.inc);

$myquery=INSERT INTO `$table` (`comments`) VALUES ('$mycomments');
$myresult=mysql_db_query($db,$myquery);
mysql_close($myconn);
echo done;
?
- 


ANd when i'm trying to see what was added on mysql, i have the following
result :
Hello My name is Panos and I\

- 

The field on mysql is TEXT
Does anyone knows how can i resolve this problem?
Thanks
Panos
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


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


Re: [PHP-DB] Dates prior to Dec 31, 1969

2004-12-14 Thread Jochem Maas
Frank Marousek wrote:
I'm using the following code to display dates returned from a query of a
mySQL database.
What kind of field is it? (int,timestamp,datetime,etc)
$new_timestamp = strtotime($row_SearchPlayerRcrdSt['Date']);
what do the following contain:
$new_timestamp
$row_SearchPlayerRcrdSt['Date']
you also might want to try connecting to the DB with the cmdline
mysql app to take a look at the date values actually stored in the DB.
$new_date_formatted = date (m/d/y, $new_timestamp);
echo $new_date_formatted;
It appears that all dates prior to Dec 31, 1969 are displayed as 12/31/69.
What am I doing wrong?
Sounds like you have yet to come across the 'unix epoch' (try googling 
that). something to do with this looks to be tripping you up.

Either the date in the DB is invalid (eg. equal to 0) or strtotime or 
date are truncating the date value in your version of php.

(what version of php  mysql?)
Also notice that you are taking a formatted date string, parsing it for 
a timestamp and then creating a new formatted date string. Why not let 
mySQL just format it how you want straight away and save 2 function calls?

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


Re: [PHP-DB] html display

2004-12-16 Thread Jochem Maas
sorry but this has nothing to do with:
1. DBs
2. PHP
3. LAMP
what your talking about is rather trivial clientside (browser) content 
styling. making a page display at a fixed width can be done in any 
number of ways, the oldest way would be to use a simple table set at the 
correct width and place all your content inside that, alternatively you 
could look into the possibilities of CSS (which if you use it properly 
should allow you to display pretty much any structural HTML how you want 
- YMMV)

heres an example, (oh and the width is 786 for a reason):
html
head
style
body { margin: 0px; border: 0px; padding: 0px; }
#container {
width: 768px;
text-align: left;
margin-left: auto;
margin-right: auto;
}
/style
/head
body
div id=container
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed 
do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim 
ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut 
aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit 
in voluptate velit esse cillum dolore eu fugiat nulla pariatur. 
Excepteur sint occaecat cupidatat non proident, sunt in culpa qui 
officia deserunt mollit anim id est laborum.
/div
/body
/html

Kevin Russell wrote:
for displays bigger than 8x6 you can use a div to border the page. for 
displays with res smaller, you're s.o.l. you cannot force the browser to a 
smaller res.

bastien

that's ok, I want it to display 8x6 if you have your display set to that, or if 
you have it set to a higher resolution I want it to display at 8x6, no matter 
if you have 1280 x whatever , you dig
thx

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


Re: [PHP-DB] _POST, _GET, _REQUEST not working

2004-12-20 Thread Jochem Maas
Warren wrote:
Hello,
I am running PHP 4.39 as a CGI under Tomcat 5.025,  Linux 2.4.20-31.9.
Configure = './configure' '--with-java=/usr/java/j2sdk1.4.2_04'
'--with-servlet=/home/www/jakarta-tomcat-5.0.25' '--with-mysql'
I cannot get the _GET function or _REQUEST functions to pick up values from
they are variables not functions.
a form generating even though I can see the query string values in the URL
as in:
http://localhost:8080/ip7/httptest.php?var1=212122var2=343434
My HTML is very simple:
form action=http://localhost:8080/ip7/httptest.php; method=get
input type=text name=var1
input type=text name=var2
input type=submit
/form
The PHP program httptest.php is also very simple:
?PHP
global $_SERVER, $_GET, $_POST, $_REQUEST, $_SESSION, $_COOKIE;
all the vars listed above are super globals you don't have to declare 
them as global - they are everywhere! this may also be the cause of the 
problem, what happens when you remove this line?

also have you tried var_dump() or print_r() on the $_GET/$_POST/etc arrays?
ps - not a very DB related question is it?
if(!empty($_REQUEST['var1'])) { $var1 = $_REQUEST['var1']; }
else { $var1 ='undefined'; }
if(!empty($_GET['var2'])) { $var2 = $_GET['var2']; }
else  $var2 ='undefined';
// Various HMTL tags removed for simplicity
echo   $var1
echo   $var1
?
I have tried everything I can think of including using HTML POST instead of
GET,  setting register_globals = On/Off.
leaving this off is recommended.
Thanks in advance.
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] Parse errors ,,, can you. impart me about it.

2004-12-21 Thread Jochem Maas
Norland, Martin wrote:
...
4) you thought this was [EMAIL PROTECTED]
that's simply hilarious! :-)
thanks Martin for making me laugh!
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] Comparing Two Values

2004-12-21 Thread Jochem Maas
Andre Matos wrote:
 Hi List,

 I was comparing two values, a current value with a new value to build 
 the UPDATE instruction and I faced this:

 Current value: 2 == new value: 0002

in short, assuming that both the variables are not integers (i.e.
2 is equal to 0002) you should use === if you want '002' to not equal '2'.
try the following lines of code:
var_dump(2 === 002);
var_dump('2' === '002');
var_dump('2' == '002');
var_dump(2 == 002);
var_dump(2 == '002');
amazing what a bit of experimentation can teach you

 So, PHP is telling me that the current is equal to the new. Is this
 possible? Any idea to avoid this problem?
this is not a problem, its the documented behaviour, actually it's the 
foundation of what makes php so easy to use - namely automatic 
typecasting and dynamic types (I am probably not explaining that too well).

read the manual to understand more:
http://nl.php.net/manual/en/language.operators.comparison.php
http://nl.php.net/manual/en/language.types.string.php#language.types.string.conversion
BTW: this is not a DB question.  ;-)

 Thanks for any help.

 Andre

 --
 Andre Matos
 [EMAIL PROTECTED]

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


Re: [PHP-DB] _POST, _GET, _REQUEST not working

2004-12-21 Thread Jochem Maas
Warren wrote:
Thanks for your response Jochem.
cheers.
I realize this is not a DB specific question but this exercise is to get my
mysql routines working.
I did remove the declaration global $_SERVER, $_GET, $_POST, $_REQUEST,
$_SESSION, $_COOKIE but still do not get values.
bummer. I have a sneaking suspicion that your problem might be related 
to the fact that you are running the cgi version of php.

Funny thing, $_SERVER[QUERY_STRING] returns the query string
one interim solution could be to write a function that fills the $_GET 
and $_POST vars - getting an array from a string like 
var1=334343var2=343434 is fairly trivial how does the following work 
for you?

parse_str( $_SERVER['QUERY_STRING'], $_GET );
print_r($_GET);
obviously this leaves you nowhere with POST  COOKIE values.
var1=334343var2=343434 but $_GET['var1'] or $_REQUEST['var1'] are empty.
which of the superglobals are actually defined at all?
phpinfo() shows
SERVER[argv] = Array
what does:
print_r( $GLOBALS );
print_r( $HTTP_GET_VARS );
print_r( $HTTP_POST_VARS );
...show you? (you might want to wrap the output in PRE tags for legibility)
(
[0] = /home/www/jakarta-tomcat-5.0.25/webapps/ip7/WEB-INF/cgi/httptest.php
probably a stupid question but: do you actually need tomcat? why not try 
a vanilla setup to begin with?

have you read this page:
http://nl.php.net/manual/en/language.variables.predefined.php#language.variables.superglobals
if not why not? (read the manual from back to front, it save you lots of 
time in the long run)

[1] = var2=343434
[2] = var1=334343
)
Very puzzling.
Anyone else?
-Original Message-
From: Jochem Maas [mailto:[EMAIL PROTECTED]
Sent: December 20, 2004 5:53 PM
To: Keane, Warren A FIN:EX
Cc: [EMAIL PROTECTED]
Subject: Re: [PHP-DB] _POST, _GET, _REQUEST not working
Warren wrote:
Hello,
I am running PHP 4.39 as a CGI under Tomcat 5.025, Linux 2.4.20-31.9.
Configure = './configure' '--with-java=/usr/java/j2sdk1.4.2_04'
'--with-servlet=/home/www/jakarta-tomcat-5.0.25' '--with-mysql'
I cannot get the _GET function or _REQUEST functions to pick up values
from
they are variables not functions.
a form generating even though I can see the query string values in the URL
as in:
http://localhost:8080/ip7/httptest.php?var1=212122var2=343434
My HTML is very simple:
form action=http://localhost:8080/ip7/httptest.php; method=get
input type=text name=var1
input type=text name=var2
input type=submit
/form
The PHP program httptest.php is also very simple:
?PHP
global $_SERVER, $_GET, $_POST, $_REQUEST, $_SESSION, $_COOKIE;
all the vars listed above are super globals you don't have to declare
them as global - they are everywhere! this may also be the cause of the
problem, what happens when you remove this line?
also have you tried var_dump() or print_r() on the $_GET/$_POST/etc arrays?
ps - not a very DB related question is it?
if(!empty($_REQUEST['var1'])) { $var1 = $_REQUEST['var1']; }
else { $var1 ='undefined'; }
if(!empty($_GET['var2'])) { $var2 = $_GET['var2']; }
else $var2 ='undefined';
// Various HMTL tags removed for simplicity
echo $var1
echo $var1
?
I have tried everything I can think of including using HTML POST instead
of
GET, setting register_globals = On/Off.
leaving this off is recommended.
Thanks in advance.

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


Re: [PHP-DB] MYSQL

2004-12-22 Thread Jochem Maas
Balwant Singh wrote:
 hi to all,

 may somebody guide me on the following:

 I want to retrieve data from MYSQL and then want that PHP do calculation
let hope your not asking how to connect to the DB. and perform a query...
 - substract a particular field from its previous row. i.e. suppose i
 have two field named DATE, STOCK and have 10 rows. Now i want that STOCK
 on the 10th row should be substracted from 9th and so on.  May pls. help
 me.
image you have an array of rows of data already retrieved from the DB 
(and each row has two items, say DATE and STOCK), lets assume that the 
order of the items is such that row 10 is first, row 9 second (easy to 
do with the ORDER BY clause of the SQL query, use ASC/DESC on the 
required field as required).

e.g. $rows.
?
// here is a fake array to simulate the data from mysql
$rows = array(
   array('STOCK' = 2), // 10
   array('STOCK' = 4), // 9
   array('STOCK' = 8), // 8
   array('STOCK' = 16),// 7
   array('STOCK' = 32),// 6
   array('STOCK' = 64),// 5
   array('STOCK' = 128),   // 4
   array('STOCK' = 256),   // 3
   array('STOCK' = 512),   // 2
   array('STOCK' = 1024),   // 2
);
$calcStockVals = $origStockVals = array();
foreach ($rows as $row) {
   $prevRow = isset($prevRow)
? $row['STOCK'] - $prevRow
: $row['STOCK'];
   $origStockVals[] = $row['STOCK'];
   $calcStockVals[] = $prevRow;
}
var_dump(array_reverse( $origStockVals ));
echo \n  \n;
var_dump(array_reverse( $calcStockVals ));
?
hope that gives you an idea.


 with best wishes
 balwant

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


Re: [PHP-DB] PHP Classes to generate Excel files ?

2004-12-22 Thread Jochem Maas
try googling on
'php excelwriter'
or
'php excel writer'
if you require more than basic CVS (hint PEAR contains a class design to 
generate functionally rich XLS files).


another cool trick (which Bastien hinted at) is to output the correct 
headers so that IE (its IE only i'm afraid) will start up an Excel 
session in the browser window all you have to do is output an 
arbitrary HTML table of data
and excel will convert it for you on the fly.

a quick google led me to this article which will probably give enough 
info to get started:

http://www.evolt.org/article/Using_MySQL_and_PHP_to_Present_Excel_Spreadsheets/20/26896/
Bastien Koert wrote:
 Don't really need a class...simply output a csv file with the correct
 headers...and excel knows to open the csv files

 bastien

 From: Stéphane Pinel [EMAIL PROTECTED]
 To: 'PHP DB' php-db@lists.php.net
 Subject: [PHP-DB] PHP Classes to generate Excel files ?
 Date: Wed, 22 Dec 2004 14:19:41 +0100

 Hello,

 I'm looking for PHP classes (free or cheap) that are able to generate
 Excel files (XML?) with a minimum
 of customization capabilities (styles, borders, colors...).

 Any idea ?

 Thanks in advance.

 Stéphane
 --
 PHP Database Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php



Bastien Koert wrote:
Don't really need a class...simply output a csv file with the correct 
headers...and excel knows to open the csv files

bastien
From: Stéphane Pinel [EMAIL PROTECTED]
To: 'PHP DB' php-db@lists.php.net
Subject: [PHP-DB] PHP Classes to generate Excel files ?
Date: Wed, 22 Dec 2004 14:19:41 +0100
Hello,
I'm looking for PHP classes (free or cheap) that are able to generate 
Excel files (XML?) with a minimum
of customization capabilities (styles, borders, colors...).

Any idea ?
Thanks in advance.
Stéphane
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

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


Re: [PHP-DB] _POST, _GET, _REQUEST not working

2004-12-22 Thread Jochem Maas
Keane, Warren A FIN:EX wrote:
Jochem wrote:

one interim solution could be to write a function that fills the $_GET 
and $_POST vars - getting an array from a string like 
var1=334343var2=343434 is fairly trivial how does the following work 

Thanks but this would be impractical for the real application. I need to
gather
customer data and write it to the database. I would likely use POST. I
couldn't 
get POST to work either but am using _GET right now since I can at least 
see the query string value. 
ok - I assume then that POST values don't appear in argv as GET values 
do? if they do then the proposition stands.


probably a stupid question but: do you actually need tomcat? why not try 
a vanilla setup to begin with?
I need Tomcat for a Java app we run and this is the standard here.
I notice that your running tomcat on port 8080, maybe its a possibility 
to run tomcat an a vanilla apache setup next to each other (no diff 
ports obviously) - one for the java webapp and one for the php stuff 
(apache with apache php sapi, preferably statically linked cos thats 
faster)...

I am guessing but I also think the problem is to do with the fact that 
the CGI sapi is being used.

a bit desperate but... you could go thru purmatationS of the following 
ini setting to see if your problem goes away:

variables_order
register_globals
register_argc_argv
register_long_arrays
if that doesn't do it maybe its time to build the webserver from scratch 
again (also is there a reason to use the CGI? - is there not a sapi for 
tomcat?)

I'm afraid I'm out of ideas, hope you figure it out!
...
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] help newbies :)

2004-12-23 Thread Jochem Maas
Nayyar Ahmed wrote:
Hello All,
I am developing attendence mangement system, its my first application
in PHP, I want to compaire the input text box value with table records
the follwing is the code
_index.htm___
..
  form name = 'loginfrm' method = post action = index.php   
  pre   /td
  /tr
  tr
td width=100% height=115html

body

div style=mso-border-alt: solid #FF .75pt; width: 675; height:
234; border: 1.0pt solid #FF; padding: 6.0pt; background:
#FF
  table border=0 cellpadding=0 cellspacing=0
style=border-collapse: collapse bordercolor=#11 width=100%
id=AutoNumber2
tr
  td width=25%font size=4User Name:/font/td
  td width=25%
  

  pinput name = uname type = text size=20/p
  /td
  td width=25%font size=4nbsp;nbsp;nbsp;nbsp; Class:/font/td
  td width=25% select name= class
 option value = BBA BBA/option
 option value = BBA-IT 
BBA-IT/option
 option value = BCS BCS/option
 option value = B.Sc B.Sc/option
 option value = MBA MBA/option
 option value = MBA-IT 
MBA-IT/option
 option value = MS-IT MS-IT/option
 option value = MS-CS MS-CS/option
 option value = Admin Admin/option
/select /td
   

  td width=25%font size=4Password:/font/td
  td width=25%input name =passwd type = password size=20 /td
etc. etc. ...
_
_index.php_
?php
$db= mysql_connect(localhost,root,masood);
mysql_select_db(attendence,$db);
 $result= mysql_query(select uname,upasswd from user,$db);
while ($myrow = mysql_fetch_array($result))
{
 if(($uname == $myrow[uname])  ($upasswd == $myrow[uname]));
firstly the preceeding line should probably be:
if(($uname == $myrow[uname])  ($upasswd == $myrow[upasswd]));

{   
echo $myrow[uname];
echo $myrow[upasswd];
}
}
?
/body
/html
this give me error no 13, with uname,upasswd undefined, please help me out,
TIA
get familiar with the var_dump() and print_r() functions. for instance 
what does the following output:

$result= mysql_query(select * from user,$db);
while ($myrow = mysql_fetch_array($result)) {
print_r( $myrow );
}
are the indexes 'uname' and 'upasswd' defined in each dumped array?


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


Re: [PHP-DB] Do you know about my lost php-mysql manual.

2004-12-23 Thread Jochem Maas
Nayyar Ahmed wrote:
Hello All,
when I was in university 4 years back , one of my teacher have given me
a php-mysql manual from 4 years back will probably be about as relevant 
as a knife in a gun fight (i.e. not very - out of date documentation is 
garanteed to cause headaches due to changes in functionality/API etc etc)

a php-mysql manual which was focused on a Jock's site development, 
what is a Jock?
unfortunatly I have lost it, but I am unable to find where I can get that
online copy. 

the following are the best places to start:
http://www.php.net/manual/en/ref.mysql.php
http://www.php.net/manual/en/ref.mysqli.php
http://dev.mysql.com/doc/mysql/en/index.html
following that there is always google... there are a few pages here and 
there discussing/explaining mysql/php usage ;-)

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


Re: [PHP-DB] still Parse errors ,,, can you. impart me about it.

2004-12-23 Thread Jochem Maas
Ford, Mike wrote:
To view the terms under which this email is distributed, please go to 
http://disclaimer.leedsmet.ac.uk/email.htm

On 23 December 2004 18:04, amol patil wrote:

hallo Mike,
thanks for reply, but i want a bit more help, again
I want a Porsche if anybody is listening.

Please keep this on-list -- someone else may have time to reply before I can
(especially as I am about to go home for my tea and a well-earned sleep!).

i know these parse errors are generally typing mistakes ,
that is the only thing they are, assuming the build of php you are 
running is okay (i'll hazard a guess you are running on some shared 
hosting or a local copy on windows - either I doubt the php binary is 
the problem), php is telling you there are syntax errors

but i have checked for it , but still i am getting errors.
i have attached files  with  their codes , can you go through
it to find what is going wrong
the attached files are stripped when going thru the mailing list.

Parse error: parse error, unexpected '' in
/home/dollar1/public_html/signup.php on line 263
this means the character '' appeared in your code where it shouldn't
e.g.
?php
$i = 0; // okay
$i = 0; // borked


parse error, unexpected '' in
/home/dollar1/public_html/login.php on line 94
Parse error: parse error, unexpected T_STRING in
/home/dollar1/public_html/addfunds.php on line 91 then on 102
T_STRING means 'String Token' (a token is an atomic syntax element, very 
roughly speaking tokens are what the php engine turns your code into so 
that it can translate it into machine code)

it means you are declaring a string where you should not, e.g. a 
misplaced opening quote:

?php
$i = 'this line is borked'';
---
in short you code is not correct. correct code does not give parse errors.
also realise that the error may not occur on the line the parser chokes 
on. often it is the preceeding line that has a typo, and in the case of 
an unmatched curly brace the error can occur at the very end of the 
script, when the offending curly brace is found somewhere at the beginning.


thank you.
Ford, Mike [EMAIL PROTECTED] wrote:
To view the terms under which this email is distributed,
please go to http://disclaimer.leedsmet.ac.uk/email.htm

On 21 December 2004 07:58, amol patil wrote:

hallo friend,
i have developed simple and small database website using php ,html
and java script. 

but i am getting these three parse errors on clicking ,
i have checked 3-4 imes on these line numbers, but there wasn't any
$ variable. php script is also correctly written.
what is this T_STRING error.
can you help me regarding this.
thank you.
errors:
Parse error: parse error, unexpected $ in
/home/dollar1/public_html/signup.php3 on line 379
$ in PHP's error messages represents the end of the file, so PHP has
reached the end of signup.php3 when it's still expecting more
program. This means you have an error somewhere in the preceding 378
lines -- most likely a missing }. (If PHP was complaining about a
variable reference, the message would refer to unexpected
T_VARIABLE.) 

Cheers!
Mike
-
Mike Ford, Electronic Information Services Adviser,
Learning Support Services, Learning  Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Headingley Campus, LEEDS, LS6 3QS, United Kingdom
Email: [EMAIL PROTECTED]
Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211

Do you Yahoo!?
Jazz up your holiday email with celebrity designs. Learn more.


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


Re: [PHP-DB] NULL VALUE

2005-01-03 Thread Jochem Maas
first off it would help if you specified what DB you are using and if 
you are using a DB abstraction lib like PEAR::DB or something similar.

also have you tried running these lines directly in a cmdline sql client?
is the status column variable width? if not then the value may be 
'Active  ' (number of padded spaces dependent on length of the field) 
instead of 'Active'.

LightBulbMoment (tm): 5 seconds of searching on the MYSQL site tells me 
STATUS is a keyword. try either renaming your field or using backticks 
to escape the name e.g.:

$query =
'UPDATE EMPLOYEE SET `STATUS`=\'Inactive\' where `STATUS` IS NULL';
I'm willing to bet you haven't bother to:
a. RT(F)M.
b. check the errors returned.
Perry, Matthew (Fire Marshal's Office) wrote:
My status column in my Employee table should have two values Active and
Inactive.  Right now all the active employees have the value Active and
the rest have a NULL value.
 

Why is it that the following commands do nothing?
UPDATE EMPLOYEE SET STATUS='Inactive' where STATUS != 'Active';
UPDATE EMPLOYEE SET STATUS='Inactive' where STATUS  'Active';
these should work - expect for the STATUS keyword issue.
UPDATE EMPLOYEE SET STATUS='Inactive' where STATUS IS NULL';
this one has a typo (extra ' at the end)
UPDATE EMPLOYEE SET STATUS='Inactive' where STATUS = '';
UPDATE EMPLOYEE SET STATUS='Inactive' where STATUS = NULL;
these 2 shouldn't work at all.
 

- Matthew
 

 

 

 

 

 

 


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


Re: [PHP-DB] NULL VALUE

2005-01-03 Thread Jochem Maas
Norland, Martin wrote:
-Original Message-
From: Jochem Maas [mailto:[EMAIL PROTECTED] 
Sent: Monday, January 03, 2005 12:16 PM
Subject: Re: [PHP-DB] NULL VALUE

LightBulbMoment (tm): 5 seconds of searching on the MYSQL site tells
me 

STATUS is a keyword. try either renaming your field or using backticks

to escape the name e.g.:

http://dev.mysql.com/doc/mysql/en/Reserved_words.html doesn't list
status, although I am familiar with its various forms e.g. show
status.
I didn't even go as far looking there I made the assumption that 
mysql was crapping out on 'STATUS' because of its use in 'SHOW STATUS' 
query (and the like) - also its hard to determine whats going wrong with 
someones setup when you have no idea what version of stuff they are 
running - bare in mind we assume the chap (Matthew Perry) in question is 
using MySQL but he did not state this so that may be incorrect.

at any rate dumping the output of mysql_error() or mysqli_error() would 
probably have saved him an email to this list. ;-)

You're probably right, but I don't exactly see this as a 'clearly
documented'.  Still, backticking all field names is a good idea anyway.
I didn't mean to say it was clearly documented (IMHO reading  
understanding documentation is one of the hardest parts of programming!) 
  but it took me exactly 5 seconds to determine with a 95% certainty that
'STATUS' was causing his query to crap out.

HINT TO 'BEGINNERS':
1. give background to your problem. (context, software versions etc)
2. show that you have taken the time to research it.
3. google on how to successfully pose a question on a mailing list - 
there are a number of very explicit essays on the subject!
4. don't give up, we have all struggled for hours/days/weeks on the 
tiniest of problems.
5. don't assume somebody will do it for you if you can't be bothered!
6. expect the occasional RTFM, even when you're doing everything right

;-)
Builds character.
:-)
Cheers,
- Martin Norland, Database / Web Developer, International Outreach x3257
The opinion(s) contained within this email do not necessarily represent
those of St. Jude Children's Research Hospital.

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


Re: [PHP-DB] NULL VALUE

2005-01-03 Thread Jochem Maas
Hi Matthew,
there are some more comments below but just for the record could you 
confirm that you are retrieving one or more rows when you issue the 
following SQL:

SELECT * FROM `employee` WHERE `status` IS NULL;
if you are getting no rows back then the obviously updating based on the 
status field being NULL will update nothing.

Perry, Matthew (Fire Marshal's Office) wrote:
I apologize for my lack of information concerning this problem and I
appreciate the advice for beginners.
I also did not mean to post it on this list (If you notice my original
message also contained a thank you for a question never asked in this list).
I am terribly sorry about this error.
well don't be too sorry :-) ... spilt milk and all that!
HOWEVER: The question can regardless be addressed in this list since it is
not appear to be version or database specific.  I am using MySQL 4.1 but
have experienced the same problem with MS SQL Server.
ok. Don't have any experience with MSSQL. (and I'm more of a 
firebird/interbase kinda guy these days)

The issue here is NOT whether STATUS is a keyword.  Yes STATUS is a keyword
and indeed it would probably be wise if I did not use keywords as column
names.  The reason I chose to leave this column named STATUS is that it is
linked to other databases (ouch!) and such attempts have proven to cause
even more problems.
ouch indeed.
But in theory this does not matter.  One can use keywords as column names in
all recent versions of MySQL even though this is unadvised (you have to
search the MySQL site for longer than 5 seconds to learn this).  The problem
;-) you are correct in this, although I would never ever use keywords as 
column names without quoting (i.e. backticks in MySQL) those names in 
all queries (even if it does work without quotes on certains 
versions/dbs/platforms/etc)

exists for all column names.  I have experimented with other test tables
with more standard column names and have had the same result.
mysql_error() or mysqli_error() also do not help here.  Even if you enter
the SQL command directly it posts a result that changes 0 rows and the query
completes without any errors.
I believe this problem lies in how SQL handles NULL values.  Let me change
lets be clear here: SQL in a generic term, there are various ANSI 
standards that define the SQL specifications BUT no one implementation 
full supports any standard - the handling of the NULL value is DB 
dependent (that is to say there will be probably inconsistencies)

[the great thing about standard is there are so many to choose from ;-)]
the column name to avoid the question concerning STATUS as a keyword.
UPDATE EMPLOYEE SET STATUS_lsdkrjg='Inactive' where STATUS != 'Active';
UPDATE EMPLOYEE SET STATUS_lsdkrjg ='Inactive' where STATUS  'Active';
UPDATE EMPLOYEE SET STATUS_lsdkrjg ='Inactive' where STATUS IS NULL';
UPDATE EMPLOYEE SET STATUS_lsdkrjg ='Inactive' where STATUS = '';
UPDATE EMPLOYEE SET STATUS_lsdkrjg ='Inactive' where STATUS = NULL;
None of these work to update table Employee.
that does not surprise me, only half of the 'STATUS' fieldnames in those 
queries have had their names changed

According to some of my SQL reference manuals they should!
I have tried the following and had success with one of these options:
create table TEST (
testA varchar(30),
testB varchar(30)
);
insert into TEST values ('a', 'a');
insert into TEST values (NULL, 'a');
+++
| testA  | testB  |
+++
| a  | a  |
| [NULL] | a  |
+++
UPDATE TEST set testA='b' where testA='';
UPDATE TEST set testA='b' where testA'a';
+++
| testA  | testB  |
+++
| a  | a  |
| [NULL] | a  |
+++
Finally I tried this:
UPDATE TEST set testA='b' where testA IS NULL;
this last statement is the proper way of doing it.
+++
| testA  | testB  |
+++
| a  | a  |
| b  | a  |
+++
But the last example does not work for ANY fields in my EMPLOYEES table.  I
thought at first the problem might have arisen with the fact that this table
is linked to other databases, but even after I removed the links this
problem exists!
I think the problem still lies with my understanding of NULL.
you should realise that you can never do something like:
SELECT * FROM mytable WHERE myfield=NULL
the reason being that the NULL value is akin to 'unknown' and having an 
unknown value be equal to another unknown value is rather illogical (at 
least that how the gurus of old decided we should live - if you catch my 
drift)

in short NULL is not equal to anything at all, ever - NULL is not even 
equal to NULL.

What am I forgetting about the nature of NULL values?
Why won't the following work for NULL values?
UPDATE TEST set testA='b' where testA='';
NULL is not equal to an empty string. see above. also check out the 
searchable online version of the manual at mysql.com where they (try to) 
explain this in alot more 

Re: [PHP-DB] MySQL database converter ?

2005-01-04 Thread Jochem Maas
Nayyar Ahmed wrote:
Hello All:
Is there any tool available for conversion of M$ Access, Oracle etc Databases
to MySQL database ?
google will probably give you more answers than this list (try also 
searching for the term 'datapump' and variations on it)

IBExpert is one tool that will allow you to reverse engineer an existing 
DB and then use the model that is created to generate SQL to create a 
new DB in the format of your choice (the 3 you mention are supported)

also bare in mind that not all features of each database can be 
translated to the others.

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


Re: [PHP-DB] Removing first word from a string?

2005-01-04 Thread Jochem Maas
Chris,
I'll try to explain the basics of a technique I often use:
imagine you have 0 or more possible where clauses. start of with an 
empty array e.g.

$whereClauses = array();
now for each clause you need add the relevant subclause as a seperate 
item to the array (DO NOT include the AND or WHERE string). e.g.

if ($foo) {
// it up to you to make sure $foo is okay for adding to a query string
$whereClauses[] =  foofield='$foo';
}
once you have gone thru all the possible subclauses that could exist do 
something like this (I'll assume $sql contains the base query):

if (count($whereClauses)) {
// we have a where statement to make
$sql = $sql . ' WHERE ' . join(' AND ', $whereClauses);
}
I leave it up to your imagination how you apply this idea!
greets,
Jochem
Bastien Koert wrote:
one simple trick is to use a clause that always evaluates correctly. For 
example, in my site I don't delete data, but flag it with a field 
(record_deleted) which defaults to 'No' (actually 0) and can be set to 
'Yes' (again 1) so that all queries are built with the requirement to 
use AND

ie
$sql = select * from tablename where record_deleted = 0 
//code to delevop additional where paramters goes here
if (!empty($_POST['city'])){
  $sql .=  AND city like '{$_POST['city']}%' ;
}//end if
you could also use the same mechanism that PHPMYAdmin does which is to 1
select * from tablename where 1
since one always evaluates to true and does not affect the query, its a 
simple way of doing the same as above


bastien
From: Chris Payne [EMAIL PROTECTED]
To: php-db@lists.php.net
Subject: [PHP-DB] Removing first word from a string?
Date: Mon, 3 Jan 2005 21:46:03 -0500
Hi there everyone,

I am building a dynamic MySQL query for a project I am working on, but 
there
are instances where it products WHERE AND instead of WHERE city etc 
.. due
to the nature of the system I am developing.  My question is, how can I
remove the FIRST  AND from a string if it is present, but leave all 
other
AND statements in the string?


I would really appreciate any help on this.  I can do a find and 
replace on
a string no problem, but just want it to be removed IF it is the FIRST 
word
in the string.


Oh and Happy New Year everyone.

Chris
--
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.296 / Virus Database: 265.6.7 - Release Date: 12/30/2004

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


Re: [PHP-DB] Display records on form

2005-01-04 Thread Jochem Maas
David Ziggy Lubowa wrote:
On Tuesday 04 January 2005 10:10, David Ziggy Lubowa wrote:
Hey guys ,
I was wondering , i have 16 records within a table in my Database , i have
managed to have a form which can add and modify the records. My only
problem is how i can display on a form when i search. Can someone give me
heads up on how i can code this in php, to display the records in a tabular
manner when i search.
how does somebody manage to create a working script to insert/update 
data in a table and not be able to figure out how to output a simple 
HTML table listing the current records?
I mean, do you want us to teach you how to write PHP? (My rate is 
40euros/hour)

--
Sorry David but your email shows little to no effort on your part to:
a, define you problem succinctly
b, show context (e.g. code,SQL snippets)
c, show that you have made a decent effort to work the problem.
given those facts you can consider yourself lucky to recieve any replies 
at all.

ANYWAY... seeing as I'm bitchin' at ya I might as well give you a small 
clue

the process, roughly speaking is:
1. do a SQL select query. (e.g. SELECT id,name FROM mytable)
2. loop thru the result, for each row output some HTML for a table row
e.g.
echo '
tr
tda href=/edit.php?id='.$row['id'].'edit/td
td'.$row['id'].'/td
td'.$row['name'].'/td
/tr'
3. don't forget to add begin- and ending TABLE tags.
try googling 'display a MYSQL result set with PHP':
I came up with:
http://juicystudio.com/tutorial/php/mysql.asp
(which is pretty funny cos the guy wrote a tutorial on mysql/php on an 
ASP based site!!)


sorry i meant 16 fields  not records : )
whether you tables has 16 rows or fields seems to me to be completely 
irrelevant.


Any help is highly appreciated.
cheers
-Z

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


Re: [PHP-DB] $_GET of array variables

2005-01-05 Thread Jochem Maas
in the script that recieve the form submission try adding the following 
lines to view the contents of the $_GET superglobal array.

echo 'pre';
print_r( $_GET );
echo '/pre';
once you see the structure it should be clear what array index key(s) 
you should be using to get to the relevant values.

PS - Matt M.'s syntax suggestion is along the right lines (although the 
actual keys you use may be different.

Matt M. wrote:
$_GET['simplevariable']  but am not having much luck with anything like:
$_GET[arrayvariable$a] (1-dimensional array) or
$_GET[arrayvariable$a$b] (2-dimensional array)
(I've tried several other odd syntaxes such as
$_GET[arrayvariable[$a][$b]].  Also it's not an \ situation.)

have you tried
$_GET[arrayvariable][$a]
or 
$_GET[arrayvariable][$a][$b]

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


Re: [PHP-DB] Display records on form

2005-01-05 Thread Jochem Maas
I'm resending this email as it does seems to have made its way onto the 
list (as far as I can see) - apologies if this is a double post.

anyone else interested in recieving the pagination function I mention 
below can mail me offlist.

here is the original reply:
David Ziggy Lubowa wrote:


first of all , let me apologize for the top post, second let me apologize for 
not giving more detail.  The main problem is basically pagination , i have 
failed to add pagination code to my own code simply because it is not as 
simple as i thought.  Considering i am a begginer in PHP , i must give myself 
some credit for reaching where i am ,  as for code snippet here goes,

...
pagination is fairly simple once you have done it a few times, It took
me ages to get my head round too.

$link = mysql_connect(localhost, me,me2);
mysql_select_db(ip, $link);
$qry = mysql_query(SELECT * FROM IP_Addresses where free like '%.
$_GET['q'].%', $link);
I think you should use the $trimmed var here iso $_GET['q'], also you
should make sure that any single quotes in this string are escaped
properly (otherwise they will break your query).
to do pagination you have to combine pagination links (that are used to
propigate the 'page number' and current query parameter) by adding:
LIMIT $i, 50
to the end of your query, where $i is a multiple of 50 (lets assume you
wish to show 50 rows per page) - $i would be equal to zero for the first
page. the value of $i has to be propigated through the pagination links
- the function I sent to you offlist has a parameter to handle this.
BTW the function I sent you returns HTML (links!) which you need to
include with your output to allow users to select different pages. Also
note that the second argument to the function is not actually used - its
merely there so that the function is also usable as a Smarty plugin.
other than using the output from the function I sent you and making use
of LIMIT clause the rest of you code does not need to change.
TIP: try to seperate processing logic from your output, i.e. breaking in
and out of PHP the whole time (using ?php ?) makes you code hard to
read/maintain. to start with you could create all ness. vars containing
dynamic content at the top of your script and then at the bottom output
the HTML (maybe even by including a file, that file would contain just
the HTML and enough PHP to output the dynamic data, the file would
assume all ness. data vars are set).
?
table border=1 width=100%tr?php
if (mysql_num_rows($qry)==0 ) {
print  Oops No records found ;
?
br
a href=http://localhost/ipsearch2.html;Back/a
/br
?
exit();
}
if (mysql_num_rows($qry)  0) {
   for ($i = 0; $imysql_num_fields($qry); $i++) {
   echo td align=centerstrong . mysql_field_name($qry, $i) . 
/td;
}
}
good for you for taking the generic route rather than hard coding you
fieldnames!
?
/tr?php
if (mysql_num_rows($qry)  0) {
   for ($j = 0; $jmysql_num_rows($qry); $j++) {
   ?tr?php
   for ($k = 0; $kmysql_num_fields($qry); $k++) {
   echo td align=center . mysql_result($qry,$j, $k) . /td;
   }
   ?/tr?php
   }
}
?
/table
br
br
a href=http://localhost/index.html;Main Page/a
br
br
a href=http://localhost/ipsearch2.html;IP Address Search/a/br/br
/br
/br
/body
/html
[/snip]
i had posted some time back that i have problems with pagination and got alot 
of help , but the problem is i have never known how to put the code together 
with what i have .. any help is appreciated...

cheers

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


Re: [PHP-DB] MySQL Auto PK

2005-01-05 Thread Jochem Maas
OOzy Pal wrote:
Dears,
Is it possible to have mysql at an ID as 20050105-1 as
(MMDD-1), -2, etc.
probably, possibly, maybe. take your pick.
as Martin Norland already pointed out to someone else; this is not 
[EMAIL PROTECTED] (that beauty of a comment is forever burned 
into my neo-cortex! :-)

i.e. try a little more info...
OOzy
=
Regards,
OOzy
What is the purpose of life?
		
__ 
Do you Yahoo!? 
Yahoo! Mail - now with 250MB free storage. Learn more.
http://info.mail.yahoo.com/mail_250

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


Re: [PHP-DB] $_GET of array variables

2005-01-05 Thread Jochem Maas

Jochem Maas wrote:
in the script that recieve the form submission try adding the following 
lines to view the contents of the $_GET superglobal array.

echo 'pre';
print_r( $_GET );
tip for those pulling their hair out: PRINT_R() is your friend!!!
...sometimes referred to as the poormans debugger.
now lets sing together: If in doubt print it out! :-)

echo '/pre';
once you see the structure it should be clear what array index key(s) 
you should be using to get to the relevant values.

PS - Matt M.'s syntax suggestion is along the right lines (although the 
actual keys you use may be different.

Matt M. wrote:
$_GET['simplevariable']  but am not having much luck with anything like:
$_GET[arrayvariable$a] (1-dimensional array) or
$_GET[arrayvariable$a$b] (2-dimensional array)
(I've tried several other odd syntaxes such as
$_GET[arrayvariable[$a][$b]].  Also it's not an \ situation.)

have you tried
$_GET[arrayvariable][$a]
or $_GET[arrayvariable][$a][$b]

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


Re: [PHP-DB] php problem

2005-01-06 Thread Jochem Maas
Serenity Schindler wrote:
I am new to php and have no idea what I'm doing wrong. I have a file named test.php containing:
 
html
head
title PHP Test /title
/head
body
pThis is an HTML line
p
?php
   echo This is a PHP line;
   phpinfo();
?
/body
/html
 
The html lines show up just fine but none of the php info is displayed. Any ideas?
does your page show you the text This is a PHP line?
if you view the source of the page in your browser do you see the following:
?php
echo This is a PHP line;
phpinfo();
?
if so then PHP is not either:
1. your webserver is not configured to use php to handle files with a 
php extension.
2. your webserver does not have php installed.

if not then try a file containing just the following and see if that 
outputs anything:

?php phpinfo(); ?
 
~Serenity~
 


-
Do you Yahoo!?
 Yahoo! Mail - You care about security. So do we.
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] PHP query to mysql database returns emtpy data, but Query Browser shows records

2005-01-06 Thread Jochem Maas
graeme wrote:
Hi,
You have:
$query example = SELECT description from cpProducts where category='39 
47 48 172'

don't you want to add a logical operator such as OR, possibly AND
$query example = SELECT description from cpProducts where category='39 
OR 47 OR 48 OR 172'

graeme.
whatever it is that he is trying to do - I doubt he wants to put 'OR's 
in the character string, besides which AFAIK you can't do something like:

SELECT description from cpProducts where category=39 OR 47 OR 48 OR 172;
(possibly the SQL above will actually return all rows because any number 
greater than zero will evaluate to true - e.g. ($x = true || 1) is 
always true regardless of the value of $x, I am assuming the same 
general logic goes for SQL or'ing)
it should be:

SELECT description from cpProducts where category=39 OR 47 OR 48 OR 172;
Jason, read on for more (possible) help (well I gave it a shot but I 
don't think it will be any help, sorry):


Jason Walker wrote:
 

Here is the query:
 function ReturnPackageDescriptions($pack, $cat, $hotcat, $hotid){
 $comIB = $cat .   . $pack .   . $hotcat .   . $hotid;
  $catLength = strlen($comIB);
  echo $catLength;
  $query = SELECT description from cpProducts where 
category=' . $cat .   . $pack .   . $hotcat .   . $hotid . ';
  echo bR . $query . br;
 echo combined package number =  . $comIB . br;
   $retval = ;
  $link = 
mysql_connect($config['host'],$config['user'],$config['pass']) or 
die(Could not connect);
  mysql_select_db('stc_store') or die(Unable to connect 
to the default database);
  $result = mysql_query($query) or die(Unable to pull 
the menu objects for main event details);
  echo mysql_affected_rows() . br;
while ($results = mysql_fetch_array($result, 
MYSQL_ASSOC)){
 extract($results);
   echo $description;
   $retval = $description;
  }
   mysql_free_result($result);
 mysql_close($link);
  return $retval;
  }

I have some extra 'echo' statements to see the progress on the web 
page. If I remove the 'where' clause within the SQL statement, I get 
rows. But when I add the 'where' portion, no records are returned.

Here is an example of what the query looks like:
$query example = SELECT description from cpProducts where category='39 
47 48 172'
I'll assume that your table has a field named 'category' - otherwise the 
statement should throw you a big error :-) BUT is it a character data 
field (i.e. does it contain text)? AND do you actually have rows where 
the value of the category field is '39 47 48 172' - in order to get rows 
returned when running your example query the value needs to match this 
string EXACTLY.

Given the fact that using mysql control center give you the desired 
result the above probably was a waste of time typing. Given that fact 
the only thing I can think of is that you have a extra space floating 
about (but I can't see it in the code your provided)

does the output of mysql_error() provide any feedback?
(what an odd problem!)

When I run the same query in MYSQL Control center or Query Browser, no 
problem. I use this function template for my SELECT statements.

Please let me know if there is something missing from the code.
Thanks.
 

 

Jason Walker
[EMAIL PROTECTED] mailto:[EMAIL PROTECTED]
http://www.desktophero.com
 


No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.298 / Virus Database: 265.6.8 - Release Date: 1/3/2005
 


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


Re: [PHP-DB] PHP query to mysql database returns emtpy data, butQuery Browser shows records

2005-01-06 Thread Jochem Maas
jwalker wrote:
No the category field is varchar(250) and uses spaces to parse each element within the field. 

The database is an osCommerce hybrid - not my own. The values within the category field go from one number to an X set of numbers, separated by spaces. This is making development rather difficult and painful.
Jason,
I thought it was something like that - sounds nasty, you poor man!
anyway can you confirm that the value in your where clause (as given in 
your example query) actually exists in the DB.

also things to try maybe:
1. test the problem on another machine
2. update php to latest release of you version (probably php4)
3. cut and paste a known value from the category field out of the DB and 
perform the query again with this value pasted into the query literally 
(rather than building the value from the various vars) to confirm the 
problem.

good luck

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


Re: [PHP-DB] str_replace question

2005-01-06 Thread Jochem Maas
Norland, Martin wrote:
-Original Message-
From: Bastien Koert [mailto:[EMAIL PROTECTED] 
Sent: Thursday, January 06, 2005 8:34 AM
Subject: Re: [PHP-DB] str_replace question

[snip]
A neat little trick would be to create the initial part of the
statement with a predefined where clause based on some record state. For
instance, we use a record_deleted field, since we don't delete data. He
could start his statement by automatically looking for it
select * from tablename where record_deleted = 'No'
then any additional clauses that get added all require the AND
keyword. No more problem
bastien

Alternatively, as mentioned before - something that evaluates to true.
The Answer**:
select * from tablename where 42
** to Life, the Universe, and Everything.
your killing me, Martin! :-)
- Martin Norland, Database / Web Developer, International Outreach x3257
The opinion(s) contained within this email do not necessarily represent
those of St. Jude Children's Research Hospital.

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


Re: [PHP-DB] str_replace question

2005-01-06 Thread Jochem Maas
Brent Baisley wrote:
I can't think of an instance where a query would have the phrase WHERE 
AND. Perhaps if you post the contents of the $additionalsql variable, 
we can tell you why it's not working.
You may actually be looking to use an array 
tried to explain that to him already, either he ignored it or its too 
complex - can't say because he never responded.

for your search words in 
str_replace(), or perhaps grep.

On Jan 5, 2005, at 8:05 PM, Chris Payne wrote:
Hi there everyone,

Im having a weird problem and Im not sure why, if I try to replace 
WHERE
AND with just WHERE it wont do it, but if I try to replace WHERE or 
AND by
themselves it WILL do it, but I cannot replace BOTH of them from a single
string, is something wrong below?


$additionalsql = str_replace(WHERE AND, WHERE, $additionalsql);

Basically Im trying to replace WHERE AND with just WHERE as Im 
building a
very complex SQL query and its a difficult one, and I have a solution 
that
works perfectly but I need this to work in order to do it.


I would appreciate any help on this, as its very important.

Chris
--
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.296 / Virus Database: 265.6.7 - Release Date: 12/30/2004

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


Re: [PHP-DB] terminates string?

2005-01-06 Thread Jochem Maas
Perry, Matthew (Fire Marshal's Office) wrote:
I am using PHP 4.3.1 and running Apache Server and MySQL.
The following question is probably only related to PHP.
 

Here is the problem:
 

I am passing the following string from one form to another:
../create.php?dest=Employee/menu_handleemployee.php?action=updateID=$ID
 

Here is the actual code:
form
action=../create.php?dest=Employee/menu_handleemployee.php?action=updateID
=?echo $ID;? method=post enctype=multipart/form-data
name=form1EMPLOYEE
 

When I view the source it comes out as expected:
form
action=../create.php?dest=Employee/menu_handleemployee.php?action=updateID
=82 

method=post enctype=multipart/form-data name=formEMPLOYEE
 

But after it goes to the next page it turns into this:
../create.php?dest=Employee/menu_handleemployee.php?action=update
Everything up to and after the '' disappears!!
that because PHP sees your URL as having two GET vars:
dest=Employee/menu_handleemployee.php?action=update
ID=82
the ampersand is the default name/value pair seperator.
try using urlencode() [and urldecode() when you actually want to 
redirect to that 'dest' url] on the redirect string when passing it 
along in the URL (or form field)

e.g.
$action = 
'../create.php?dest='.urlencode(Employee/menu_handleemployee.php?action=updateID=$ID);


and if that doesn't work try replacing the '' char with something else e.g.
$action = 
'../create.php?dest='.str_replace('','$$',Employee/menu_handleemployee.php?action=updateID=$ID);

and then before your redirect to that url reverse the replacement e.g.:
header('location: ' . 
str_replace('$$','',Employee/menu_handleemployee.php?action=updateID=$ID));
exit;


BTW: 2 dollar signs may not be the best choice of chars to use.

another way of tackling the issue is by looking at the contents of 
$_SERVER (a auto superglobal var, just like $_GET, $_POST etc) - try:

print_r($_SERVER);
you'll be surprised what kinds of useful items are contained in that array.
while you're at it try:
print_r($_GET);
looking at the output of that will probably help you understand where 
the 'ID' bit of the redirect url went.

RANT
print_r() is your friend USE IT!!! OFTEN!!!
sing this as a reminder When in doubt print it out
[ (tm) Wong Coding Industries ;-) ]
/RANT
 

The goal of this code is to send the redirect address to the form that
modifies my data. 

I want variable dest to be used to dynamically redirect the page.
 

I have tried the following to fix the problem without avail:
1) I tried saving the variable in other ways such as text fields in the form
itself.
2) I tried addslashes() (which works well with similar problems related to
',  etc.).
3) I tried adding \ before 
4) I danced around my computer and threatened to pull the plug.
you forgot to wave the dead chicken around your head!
None of these worked!
 

 

What is it about '' that throws everything off with PHP variables?  It
doesn't seem to be a problem with HTML.
its the default request name/value pair seperator.
This is exceedingly difficult to research online because '' is excluded
from most search engines automatically.
it's called an ampersand. which might help further searching.
 

-Matthew
 

 

 


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


Re: [PHP-DB] Stopping display of DB errors

2005-01-06 Thread Jochem Maas
Todd Cary wrote:
When I run a query using Interbase and if an error occurs, the error 
displays in the browser window even though I am testing for errors.  Is 
there a way to prevent this?

 function db_insert_logon_session($dbh, $sessionid, $offset) {
   $fulldate = date(m/d/Y H:i:s,time() + $offset);
   $stmnt = INSERT INTO SESSION (SES_ID, SES_EXPIRE)  .
VALUES( . $sessionid . , .
' . $fulldate . ');
//echo('Query: ' . $stmnt . 'br');
OK Todd, listen the fuck up :-)
you are missing one of the greatest things about the interbase 
extension, parameterized queries, try doing it like this:

$fulldate = date(m/d/Y H:i:s,time() + $offset);
$stmnt = 'INSERT INTO SESSION (SES_ID, SES_EXPIRE) VALUES(?,?)'
$sthdl  = @ibase_query($stmnt,$dbh, array($sessionid,$fulldate));
do it like that and you have just made SQL injection hacks an 
impossiblity :-), and stray quotes in text strings being entered into 
the DB will never again break your queries.

suck on that MySQL.
   $sthdl  = ibase_query($stmnt,$dbh);  -- displays error regardless
$sthdl  = @ibase_query($stmnt,$dbh);  -- shouldnt displays error
   if ($sthdl) ibase_commit();
   else print(Error:  . ibase_errmsg() . br);
   return $sthdl;
 };
BTW: the interbase extension was rewritten for PHP5, I don't know 
whether this was backported to PHP4 - the guy that did it is a friend of 
mine though so I'll ask about that - anyway the reason that I mention 
this is is that I don't have your problem and I use PHP5 for my 
firebird/php (the interbase extension is also used for firebird)

having said that I have a custom DB class for interbase/firebird which 
uses the following construction:

$res = call_user_func_array('ibase_query', array_values($args));
this is to do with parameterized queries (the number of args is 
obviously variable).


for anyone who reads this far know this:
Todd is a superior human being cos he uses a superior DB ;-)
MySQL is a single-celled organism next to the space-faring superbeing 
that is firebird (ok interbase too, but that aint open source)

(flame on baby!)
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] MySQL Auto PK

2005-01-06 Thread Jochem Maas
Andrew Kreps wrote:
...
20050105-1
20050105-2
20050106-1
...etc.
This would be a great place for a stored procedure, but I don't know
if I can recommend running MySQL 5 to you.  The most platform-safe way
an open source alternative that does offer this enterprise level 
functionality (stored procedures) is firebird. and its based on proven 
tech. (interbase), not to mention its not bleeding edge (firebird stayed 
in beta so long that if it had been a microsoft product it would have 
gone gold, shipped, and been put to pasture ;-).

but firebird is a little more difficult to get into than MySQL and you 
may not have access to hosting that provides it.

I can think of is to get a count(*) of the number of rows with today's
date, add 1 to it, and stick that number on the end of the string
you've created to insert into a varchar field.  It's an extra query
per insert, but it'd do the job.
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] Warnings and Notices

2005-01-06 Thread Jochem Maas
Jason Davis wrote:
I just got the software I was fighting with working. Only issue now is that
the top of the page is filled with notices and warnings, even though the
code is working. Is there any way to turn off or hide these notifications?
read them and fix your code is one way.
another is to turn down error reporting:
http://nl2.php.net/error_reporting
Jason
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] Trying to connext to MySQL with PEAR

2005-01-06 Thread Jochem Maas
Ford, Mike wrote:
To view the terms under which this email is distributed, please go to 
http://disclaimer.leedsmet.ac.uk/email.htm

On 06 January 2005 16:39, Jochem Maas wrote:

Hutchins, Richard wrote:
echo $dsn; $isPersistant = TRUE;
doesn't effect the code but 'Persistant' is spelled 'Persistent'

Oh dear, as a fully-paid-up pedant, I'm afriad I can't resist this one:
Doesn't affect the answer, but this occurrence of 'effect' should be
'affect'. ;)
DOH! :-)
Cheers!
Mike
-
Mike Ford,  Electronic Information Services Adviser,
Learning Support Services, Learning  Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Headingley Campus, LEEDS,  LS6 3QS,  United Kingdom
Email: [EMAIL PROTECTED]
Tel: +44 113 283 2600 extn 4730  Fax:  +44 113 283 3211 
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP-DB] I'm trying to out perform Martin Norland....

2005-01-06 Thread Jochem Maas
in terms of helpfulness and volume of replies to Q's on this list 
;-)  but it doesn't help that my mails seem to take hours to reach the 
list (Martin's keep beating mine to show up).

is the list-server against me? or do others also see loads of lag?
rgds,
Jochem
PS - as an even bigger kick in the face - I had the term 'o f f t o p i 
c' (without the spaces) and the list bounced my message:

php-db@lists.php.net: host pair1.php.net[216.92.131.4] said: 550 
Apparent off-topic email rejected. (in reply to end of DATA command)

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


Re: [PHP-DB] SQL statement

2005-01-07 Thread Jochem Maas
PHPDiscuss - PHP Newsgroups and mailing lists wrote:
Hello everybody,
I'm building a small application and I have trouble passing a POST
variable form one page to another inside the SQL statement.
The query displayed below works great without the
.$_POST['CompanyName']. 

$query_company_listing = SELECT CompanyID, CompanyName,
CompanyOrDepartment, BillingAddress, City, PostalCode, PhoneNumber FROM
company WHERE company.CompanyName=.$_POST['CompanyName'].  ORDER BY
CompanyName ASC;
you need to quote the string (company name) in the actual sql, compare 
the following 2 statements (lets assume companyname is 'IBM'):

WRONG (this is what you are doing now):
SELECT CompanyID, CompanyName,CompanyOrDepartment, BillingAddress, City, 
PostalCode, PhoneNumber FROM company WHERE company.CompanyName=IBM 
ORDER BY CompanyName ASC

RIGHT:
SELECT CompanyID, CompanyName,CompanyOrDepartment, BillingAddress, City, 
PostalCode, PhoneNumber FROM company WHERE company.CompanyName='IBM' 
ORDER BY CompanyName ASC

there may be times when the companyname contains a single quote - that 
will break your query unless you escape the single quote in the name 
before placing the string into the query string... mysql.com can tell 
you more.

But it messes up if I include it because the first  is considered as the
end of the previous one and so on, so the code gets messed up.
I'll really appreciate any/all help!
Have you all an excellent year!
Jorge
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] setFetchMode problem with mssql/w2003/php503

2005-01-07 Thread Jochem Maas
ltlists wrote:
I'm getting this error when attempting to use setFetchMode() 

PHP Fatal error:  Call to undefined method DB_result::setFetchMode()
in new.php on line 27
which means that class DB_result does not have a setFetchMode()
method. did you read past the colon (:) in the error message?
did it cross your mind to search for the class that does contain that
method??

My code looks like this for now, almost the same as some of the
samples getting around:
$db = DB::connect(mssql://blah:[EMAIL PROTECTED]/blah);
if (DB::isError($db)) {
die ($db-getMessage());
}
$res=$db-query(select * from Contacts);
if (DB::isError($res)) { 
 print $res-getMessage() . \nDetails: 
  .$res-getUserInfo();
} else { 
$res-setFetchMode(DB_FETCHMODE_ASSOC);

If looks as if you are trying to call the setFetchMode() method
on the 'resultset' object in your first example and in your second 
example (the function) you are calling the same method on the 'db' 
object. so this might work better:

$db-setFetchMode(DB_FETCHMODE_ASSOC);
I'm assuming $db is actually a a valid object of class DB
$row=$res-fetchRow();
$field0=$row['ID'];
$field1=$row['Name'];
$res-free();
$db-disconnect();
}
Just incase this could be an installation related problem I should
explain that I am using this in a virtual PC environment with IIS6,
PEAR was downloaded via a normal machine and then copied to the
virtual PC and go-pear was run (I think that's it).
A function based connection like this:
function execute_query($db,$sql) {
debug($sql);
$db-setFetchMode(DB_FETCHMODE_ASSOC);
return $db-getAll($sql);
}
seems to return data instead of erroring out.
I'm just a bit lost as to why the first lot of code has a problem
with DB_result.
If anyone can help that would be great.   
Thanks for your time.

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


Re: [PHP-DB] SQL statement

2005-01-07 Thread Jochem Maas
Jason,
can you please turn off the return receipts on emails you send to the list.
it's bloody annoying to have 'The Sender wishes to be notified' 
popup messages everytime I read one of your emails (and, alas, I don't 
have the skill to hack the return receipt crap right out of Tbird). BTW 
your not the only one that has it turned on - so this goes to the rest 
of you as well

:-)
cheers!

Jason Walker wrote:
First off - $_POST['CompanyName'] is valid, right?
...
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] select text from a text file

2005-01-07 Thread Jochem Maas
Ed wrote:
Hi,
Thanks for answering the question.
I'm going to make it write to a database rather than text file after
searching google and coming accross common problems with text files.
I've now just got to figure out how to mark the message as read in the
database so it does not re-appear next time the user clicks update.
TIMESTAMP? you can save in the session when a use last grabbed messages 
(clicked update) and only return newer messages (i.e. message have a 
'created' timestamp) then update the timestamp in the session. there is 
a window in which it is possible to have a request inserts a new message 
in between another request's selecting of all new messages and updating 
the session timestamp value (in such cases the person at the client end 
of the second request will never see the new message insert in the first 
request) - to handle that you have to implement some kind of locking 
mechanism.

good luck is all can say. (PHP implements a 'share nothing' architecture 
- not, perse, the easiest or most efficient type of system to build 
realtime multi-user environments in - AFAICT)

I'm going to build a function that will put the message in the correct table
using an if clause, is that the best method?
your the best judge of that - heh if it works that's the main thing - 
making it work fast that's something to look at later... and then there 
is the issue of writing code that neat, tidy, well commented and 
readable 6 months down the line.

Ed
- Original Message - 
From: Andrew Kreps [EMAIL PROTECTED]
To: Ed [EMAIL PROTECTED]; php-db@lists.php.net
Sent: Thursday, January 06, 2005 6:55 PM
Subject: Re: [PHP-DB] select text from a text file


On Wed, 5 Jan 2005 11:58:59 -, Ed [EMAIL PROTECTED] wrote:
Happy new year folks!
The titlemight make this seem like an easy to answer question
However here's the complicated bit (well for me anyway).
In my text file that is written to by the users in a chatroom it looks
like this:
nickname||color||what the user is saying||user
how can i make it so that if they have a private message when they press
update it pulls the message from the text file and displays it in the frame
but also deletes the text?
You should be using a database for this, it makes things so much
easier.  That being said, here's one way to go about the text file
version:
Open the file, read through it line by line.
As you read it, push the lines into an array.
If you find a private message for the user, store that in a variable,
and do not push it into the array.
Finish reading the file.
If there's a private message, you've got it in a variable, and you can
overwrite the private message file with the array you've stored, which
is all of the current private messages minus the one you're about to
display.
Please note, this does not scale at all, especially in the fast-paced
world of chat rooms.  You will likely end up with file locking
problems if you proceed with the flat-file method.

Also, how can i make it so that if in a drop down menu they select the
word everybody it goes to a file called messages.txt and if they select
user or user2 or user3 from the list it writes to private.txt is this
at all possible? user and user2 etc arent hardcoded it's pulling the names
from a list of online users.
Are you talking about appending messages to a text file?  In that
case, you can have the dropdown submit with the message, and in the
PHP code have a case for 'everybody' where it writes to messages.txt,
and if it's not 'everybody', write it to private.txt with the username
that was selected from the dropdown as part of the row.
Does that answer your question?
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


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


Re: [PHP-DB] select text from a text file

2005-01-07 Thread Jochem Maas
Ed wrote:
Hi,
The timestamp idea is an intresting idea and i'll give that method some
thought. I only want it to pull one private message at a time out of the
private message field so it might start getting very messy doing that
method - but it certainly does make it worth considering.
I see (I think) - the timestamp idea was aimed at a public general list 
of messages. in the case of private messages - they are always aimed at 
one particular user therefore in such a case a simple flag (true/false) 
to state whether its been viewed would probably work - or you could just 
delete the last grabbed message after you have selected it for output.

have fun!
Ed
- Original Message - 
From: Jochem Maas [EMAIL PROTECTED]
To: Ed [EMAIL PROTECTED]
Cc: php-db@lists.php.net
Sent: Friday, January 07, 2005 11:37 AM
Subject: Re: [PHP-DB] select text from a text file


Ed wrote:
Hi,
Thanks for answering the question.
I'm going to make it write to a database rather than text file after
searching google and coming accross common problems with text files.
I've now just got to figure out how to mark the message as read in the
database so it does not re-appear next time the user clicks update.
TIMESTAMP? you can save in the session when a use last grabbed messages
(clicked update) and only return newer messages (i.e. message have a
'created' timestamp) then update the timestamp in the session. there is
a window in which it is possible to have a request inserts a new message
in between another request's selecting of all new messages and updating
the session timestamp value (in such cases the person at the client end
of the second request will never see the new message insert in the first
request) - to handle that you have to implement some kind of locking
mechanism.
good luck is all can say. (PHP implements a 'share nothing' architecture
- not, perse, the easiest or most efficient type of system to build
realtime multi-user environments in - AFAICT)

I'm going to build a function that will put the message in the correct
table
using an if clause, is that the best method?
your the best judge of that - heh if it works that's the main thing -
making it work fast that's something to look at later... and then there
is the issue of writing code that neat, tidy, well commented and
readable 6 months down the line.

Ed
- Original Message - 
From: Andrew Kreps [EMAIL PROTECTED]
To: Ed [EMAIL PROTECTED]; php-db@lists.php.net
Sent: Thursday, January 06, 2005 6:55 PM
Subject: Re: [PHP-DB] select text from a text file



On Wed, 5 Jan 2005 11:58:59 -, Ed [EMAIL PROTECTED] wrote:

Happy new year folks!
The titlemight make this seem like an easy to answer question
However here's the complicated bit (well for me anyway).
In my text file that is written to by the users in a chatroom it looks
like this:

nickname||color||what the user is saying||user
how can i make it so that if they have a private message when they
press
update it pulls the message from the text file and displays it in the
frame
but also deletes the text?

You should be using a database for this, it makes things so much
easier.  That being said, here's one way to go about the text file
version:
Open the file, read through it line by line.
As you read it, push the lines into an array.
If you find a private message for the user, store that in a variable,
and do not push it into the array.
Finish reading the file.
If there's a private message, you've got it in a variable, and you can
overwrite the private message file with the array you've stored, which
is all of the current private messages minus the one you're about to
display.
Please note, this does not scale at all, especially in the fast-paced
world of chat rooms.  You will likely end up with file locking
problems if you proceed with the flat-file method.


Also, how can i make it so that if in a drop down menu they select the
word everybody it goes to a file called messages.txt and if they
select
user or user2 or user3 from the list it writes to private.txt is
this
at all possible? user and user2 etc arent hardcoded it's pulling the
names
from a list of online users.

Are you talking about appending messages to a text file?  In that
case, you can have the dropdown submit with the message, and in the
PHP code have a case for 'everybody' where it writes to messages.txt,
and if it's not 'everybody', write it to private.txt with the username
that was selected from the dropdown as part of the row.
Does that answer your question?
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




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


Re: [PHP-DB] Fetch data from dbf file?

2005-01-07 Thread Jochem Maas
Supri anto wrote:
hi all,
did anyone know how to fetch data from dbf file (Clipper) ? 
use some code.
don't expect too much help if all you can be bothered to write are
single line questions.
I googled 'DBF + PHP' and came up with this:
http://half2.mirrors.phpclasses.org/browse/package/1302.html
now I'm pretty sure they have google in your country too, so why don't
you use it before coming onto a mailing list and expecting other people
to do your research for you?
best regards,
suprie
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] String Parsing/Escaping

2005-01-09 Thread Jochem Maas
hi Alexander,
interesting question regarding 'safety' v. readability v. speed - I'm 
sure you'll get different views depending on who you ask.

Here is my take:
Alexander Mueller wrote:
Hi,
below are three versions of an SQL call along with escaping the passed 
value.

  $value=mysql_escape_string($_POST['value']);
  mysql_query('SELECT * FROM table WHERE field='.$value.'');
  + Fastest Code
  - Con: Bad Readability, Value needs to be escaped separately
I rate speed as the least important issue - you can alway use a faster 
machine, get some more RAM etc if you really need a quick speed fix.

making the code faster is the last exercise I do in any given project, 
and I almost always choose readability/'safety' over speed


  $value=mysql_escape_string($_POST['value']);
  mysql_query(sprintf('SELECT * FROM table WHERE field=%s', $value));
  + Good Readability
  - Value needs to be escaped separately

This is a compromise - can't imagine why anyone would choose this one.
It's not my choice, I'll just skip to number 3 :-)
sql_sprintf() is a custom version of sprintf() which automatically 
escapes all passed parameters.

  mysql_query(sql_sprintf('SELECT * FROM table WHERE field=%s', 
$_POST['value']));

  + Good Readability, Value does not need to be escaped separately
  - Slowest Code
YEAH!
indeed its the slowest. but its so much more readable and you know its 
alot more maintainable (you don't have to change the escaping, 
sprintf'ing strategy in 100 places.).
Its safer too because there is no chance of forgetting to escape the sql 
args.
I think the speed difference can be measured in milliseconds - are you 
really worried about that? if your app is that heavy that you are trying 
to shave off milliseconds to make it usuable then there are possibly 
bigger problems.
Imagine you have a highly dynamic page that does 50 queries (using the 
3rd technique you proposed), I would guesstimate that refactoring the 
code to do 2-3 less queries per request would get just as much speed 
increase (if not more) than by refactoring the code to use the 1st 
technique on all 50 queries (granted you could refactor both but heh 
there are other things to do than code PHP 24/7 ;-)

in order of importance to me (I often have to maintain/update my code):
1. security
2. readability/maintainability
3. speed/performance
basically the more abstract your code is, the slower it will be - 
because you are asking it to do more for you. to me the extra 
milliseconds wait on a request are worth it, anything to avoid 
debug/maintainance hell!

And if speed really is a big issue - you may need to look into writing 
part of you application logic as a PHP extension (i.e. in C which is way 
faster anyway you cut it.)


...
Thanks,
Alexander
PS: All this code is considered to run under magic_quotes_gpc OFF.
as it should be ;-)

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


Re: [PHP-DB] MySQL ENCRYPT help!

2005-01-09 Thread Jochem Maas
Kevin the Linux User wrote:
To the PHP Database Mailing-List:
	I joined the mailing list for this one question I just can't figure out. 
nice, we help you and then you bugger off? - community spirit are go!
I used the phpMyAdmin to create table. I placed one row in this table, I used 
the ENCRYPT function. How do I De-Crypt the data I just encrypted to use in my 
PHP code. I encrypted it, for security.
If it's not a bother, can you also give a sniplet of example code, on 
just the part of de-crypting it, I know everything about connecting, and 
displaying, it's just the de-crypting I am having trouble with.
the mysql manual states:
ENCRYPT() ignores all but the first eight characters of str, at least 
on some systems. 

this is probably not what you want, besides which AFAICS its one way 
encryption.

---
as you don't state what it is your trying to achieve (e.g. storing a 
passwd - in which there is NO reason to want to decrypt it - instead you 
should test a user given value against the DB by encrypting the user 
value), you also don't state what version of MySQL your using therefore 
its impossible to determine which encryption functions you have at your 
disposal in MySQL.

here is a couple of pairs of enc/dec funcs that might help:
AES_ENCRYPT(str,key_str)
AES_DECRYPT(crypt_str,key_str)
DECODE(crypt_str,pass_str)
ENCODE(str,pass_str)
try reading this page:
http://dev.mysql.com/doc/mysql/en/Encryption_functions.html
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] Update multiple records

2005-01-10 Thread Jochem Maas
Norland, Martin wrote:
-Original Message-
From: Stuart Felenstein [mailto:[EMAIL PROTECTED] 
Sent: Monday, January 10, 2005 10:40 AM
Subject: [PHP-DB] Update multiple records 

Having a problem here with updating multiple records in a table.  
[snip]
Lets see - where to begin...

SELECT * FROM `Profiles`   
INNER JOIN `Profiles_Industries` ON Profiles.ProfileID
= Profiles_Industries.ProfileID)
INNER JOIN IndTypes ON Profiles_Industries.IndID =
IndTypes.CareerIDs)
INNER JOIN SU ON (Profiles.kID = `SU.kID)
WHERE Profiles.ProfileID = colname 
[snip]
You list nothing indicating any sort of update, so forget that for the
time being until things are working.  That's your end goal, but it
doesn't look to be what you're fighting with now.  You have a very
complicated (perhaps messy, perhaps not - it might all be required)
select, and then you're trying to pull that information out and populate
a select.

INNER JOIN SU ON (Profiles.kID = `SU.kID)
[snip]
This line in particular clearly warrants attention.  Cookie to whoever
guesses what the' problem` might 'be.
that will be a lone backtick then :-) now where's the cookiejar ;-)

?php $selected =
explode(,,$rsLPInds-Fields('IndID')); 

 while(!$rsInds-EOF){
?
 option value=?php echo
$rsInds-Fields('CareerIDs')?
  ?php if
(in_array($rsInds-Fields('IndID'),$selected)) { echo selected; } ?
  ?php echo
$rsInds-Fields('CareerCategories')?/option
[snip]
explode() turns an array into a string, you'll have trouble
in_array()ing a string.  You may want to start there.
er Martin, no it does not. explode creates an array.
the manual defines it as thus:
array explode ( string separator, string string [, int limit])
possibly you got mixed up with implode() (or join() which is an alias of 
implode())

You don't list the select bit around your select, I'm assuming it's
there - what actual behavior/output are you seeing?  View source to be
sure - you have to specify a select is a multiselect, otherwise it will
just be a dropdown and select the first one you say is selected (or
maybe the last, I've not messed with it in some time - actually, it's
browser dependant, but I think they all tend to behave the same.)
rsLPInds-Fields and rsInds-Fields - this is two objects/tables/etc. -
you only mention the one, so it's hard to follow what data's where - to
be sure.
Try that stuff and get back to us.  You definitely want to be using
print_r() (possibly in pre tags) to see what information is actually
stored in the results of your select statement, if there is any question
there.
- Martin Norland, Database / Web Developer, International Outreach x3257
The opinion(s) contained within this email do not necessarily represent
those of St. Jude Children's Research Hospital.

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


Re: [PHP-DB] Update multiple records

2005-01-10 Thread Jochem Maas
Stuart Felenstein wrote:
Having a problem here with updating multiple records
in a table.  

as Martin Norland (a heavy hitter on this list AFAIKT) already stated 
you don't seem to be at the stage of actually doing an update, no big 
deal - only you are doing yourself an injustice by given a misleading 
subject. stick to the matter at hand (one step at a time!) - by all 
means explain the context of the problem (e.g. your goal of multiple 
updates) but don't confuse the problem with the context!


I'm sure this is all most likely confusing. :) Typical
I took one look and thought 'no thanks',  if _you_ think _your_ post is 
confusing how is anybody else supposed to make head or tail of it.

post from me ...sorry.  None of this is working
though. 
don't be sorry, be pro-active and rewrite it until its idiot proof. its 
in your own best interest - the clearer you state your problem the 
greater the chance someone will/can help you.

ok, so that was a bit of a rant, the idea being to educate people in the 
value of taking the time (and it often takes lots of time!) to formulate
their problems (and what they have tried so far) properly - its in 
everyones interest because it increase the potential of everyone on the 
list to:

a, get involved
b, learn something new
we want you to succeed, if only for the selfish reason that one day 
you'll have the capability to help out others. besides the more good PHP 
hackers there are the better it is for all of us - in terms of the 
perceived validity of PHP (especially at the enterprise level).

Perhaps updating multiple records is more difficult
then I first imagined. 
alas we all have stories of spending countless hours trying to figure 
out whats seems to be very simple problems!

Can anyone lend some advice , assistance ?
not directly, but you may want to look into making your code more 
readable/flexible by not constantly switching in and out of PHP mode 
(i.e. using ?php ? everytime you want to output something.)

Thank you,
Stuart
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] Update multiple records

2005-01-10 Thread Jochem Maas
Norland, Martin wrote:
-Original Message-
From: Jochem Maas [mailto:[EMAIL PROTECTED] 
Sent: Monday, January 10, 2005 11:59 AM
Subject: Re: [PHP-DB] Update multiple records
...
That's what I get for troubleshooting before lunch!
My apologies to the list and to anyone unfortunate enough to find that
post with a search!  I always get implode/explode mixed up (I think of
an array as more organized than a string - so I think of a string as
just an array that's been blown to smithereens).  I guess the idea is
that an array is like a bunch of pieces of a string after it's been
blown up.
thats actually why I personally always use join() instead implode().
also it does help beginners, the fact that its possible to use 'array
syntax' on strings e.g.:
$str = 'mystring';
echo $str[1] . ' me God?';
// echos 'y me God?' - say it out loud people ;-)

I even checked the manual and dyslexically read it.  'Spose I owe
everyone a cookie, and Jochem Maas two (plus first pick!).
I quick google lead me to suspect Martin is american... if that is true 
then I demand one of those bigass cookies with even bigger chocolate 
chips :-)


Cheers,
- Martin Norland, Database / Web Developer, International Outreach x3257
The opinion(s) contained within this email do not necessarily represent
those of St. Jude Children's Research Hospital.

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


Re: [PHP-DB] Update multiple records

2005-01-10 Thread Jochem Maas
Stuart Felenstein wrote:
--- Jochem Maas [EMAIL PROTECTED] wrote:

don't be sorry, be pro-active and rewrite it until
its idiot proof. its 
in your own best interest - the clearer you state
your problem the 
greater the chance someone will/can help you.


I don't know about anyone else, but I haven't got a clue as to what the 
problem is. I know I'm fairly intelligent but I can't work it out.

Well I've started with a clean slate.  Meaning I
always a good plan!
ditched what was starting to look like spaghetti and
started over with a lot of print_r's.  

My select statement in the (intended)update page has 3
is it an update script or a selection/view script or both?
parameters in the where statement, that are passed
over from the link using $GET_VARS.  1- is the
recordID, 2-the userID 3-an encrypted code tied to the
user.
so you start with a page that submits three values to another page
which works so that not the problem...
All those parameters show up fine (print_r) on said
update page.
The first problem I'm having is getting the update
page to show which values currently exist.  
what values are you talking about? currently exist where?
This is
the multi select box and the (adodb) recordset listing
all the options.  I'm lacking something in the page
though that allow it to see which values are already
chosen in the database:


select name=inds[] size=8 multiple id=inds[]
?php
while(!$rsInds-EOF){
?
option value=?php echo
rsInds-Fields('CareerIDs')?
?php if (count($IndID)  0 AND is_array($IndID)) {
use  not AND unless you know what your doing! they are different.
also you check the count() on $IndID before you check its an array!
another thing:
$IndID and $rsInds are pretty meaningless to the rest of the world, and 
they will be to you as well in 6 months time! use a few extra chars and 
give the vars meaningfully, easily idenfiable names (helps us guess what 
you are doing too!)


foreach ($IndID as $ind) { ?
?php if ($rsInds-Fields('IndID')== $ind) {echo
SELECTED;} } }?
?php echo
$rsInds-Fields('CareerCategories')?/option
?php
$rsInds-MoveNext();
}
$rsInds-MoveFirst();
that looks evil; seeing as I a still have no idea what your actually 
stuck on I'll give you a quick lesson in writing neater/better code:

// begin code sample ---
$opts  = array();
$IndID = (array) $IndID;
while (!$rsInds-EOF) {
/* is this option selected? */
$selected = in_array($rsInds-Fields('IndID'), $IndID)
  ? 'selected=selected'
  : ''; 
/* build the option */
$opts[] = sprintf('option value=%s %s%s/option',
  rsInds-Fields('CareerIDs'),
  $selected,
  $rsInds-Fields('CareerCategories'));

$rsInds-MoveNext(); 
}
/* output the complete select element,
 * you don't have to output directly!!!
 * you could stuff the strings into another
 * var and echo it out later (e.g. after all
 * processing has been done)
 */
echo 'select name=inds[] size=8 multiple id=inds[]';
echo join(\n, $opts);
echo '/select';
$rsInds-MoveFirst();
// end code sample ---
excuse the strange layout
a, I like short lines.
b, I find tertiary if statements very readable when spread across 
multiple lines.
c, I'm try to avoid nasty linewrap due to mail setups.

BTW - the above is not syntax checked.
anyone care to say this is _not_ more readable?
 
I've added this in the script, which prints out fine
once I've submitted the page.  Not sure if I need
something similar for the records that already exist ?
neither do I!
if (count($inds)  0 AND is_array($inds)) {
$ind = '.implode(',', $inds).';
}
looks like you want to do a select statement with $ind in the form of
SELECT * FROM yourtable WHERE yourfield IN ($inds)
heh why not!
Stuart
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] ssh tunneling with phpmyadmin

2005-01-10 Thread Jochem Maas
Jason Wong wrote:
On Tuesday 11 January 2005 11:39, Graham Anderson wrote:
is it possible to ssh tunnel with phpmyadmin
I want to access my remote db [on shared server] from my phpmyadmin on
my laptop
my ISP wonderfully disabled phpmyadmin's relational features :(
seems a bit hard to find the info so I thought I would ask here :)
I am using Mac OS X if it matters

Assuming you're able to SSH into the server from your laptop then run this on 
your laptop:

  ssh -fN [EMAIL PROTECTED] -L 13306:127.0.0.1:3306
classy tip!
Then configure your laptop's copy of phpmyadmin to access MySQL using address 
127.0.0.1 and port 13306.

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


Re: [PHP-DB] LEFT joins

2005-01-12 Thread Jochem Maas
Han wrote:
Hi,
I'm having a problem with some joins.
My code is : --
SELECT b.fldName, b.fldEmail, b.fldCountryCode, b.fldMobile, a.fldTime as Time, 
c.fldUsername FROM tblSubscribersChoices a INNER JOIN tblUser c on 
a.fldChoice=c.fldClientID LEFT JOIN tblSubscribers b on a.fldClientID = b.fldID 
ORDER BY `c`.`fldUsername` ASC
Now this works fine.
But, I'm trying to tally the country code with it's actual name (which is held 
in tc_countries). So I thought if I add another LEFT JOIN at the end of the 
query : --
SELECT b.fldName, b.fldEmail, b.fldCountryCode, d.fldCode as FCode, 
b.fldMobile, a.fldTime as Time, c.fldUsername FROM tblSubscribersChoices a 
INNER JOIN tblUser c on a.fldChoice=c.fldClientID LEFT JOIN tblSubscribers b on 
a.fldClientID = b.fldID LEFT JOIN tc_countries d on b.fldCountryCode = 
d.fldCode ORDER BY `c`.`fldUsername` ASC
But this just times out as it's matching too many matches.
What am I doing wrong???
your not using the correct SQL, obviously :-) - that said there often 
many ways to get the result you want.

what happens if you change the second SQL statement you quoted to:
SELECT DISTINCT b.fldName, b.fldEmail, b.fldCountryCode, d.fldCode as 
FCode, b.fldMobile, a.fldTime as Time, c.fldUsername FROM 
tblSubscribersChoices a INNER JOIN tblUser c on 
a.fldChoice=c.fldClientID LEFT JOIN tblSubscribers b on a.fldClientID = 
b.fldID LEFT JOIN tc_countries d on b.fldCountryCode = d.fldCode ORDER 
BY `c`.`fldUsername` ASC

(I added the keyword DISTINCT to the query)
Also you are using an INNER JOIN for the first join and A LEFT JOIN for 
the second one. what happens when you replace the INNER JOIN with a LEFT 
JOIN?

Han.

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


Re: [PHP-DB] LEFT joins

2005-01-12 Thread Jochem Maas
BTW: Hans please use 'reply to all' so that the rest of the list can see 
your replies (+ it makes me feel less like you personal help-desk ;-).

...on to the reply proper:
Han wrote:
Hi, thanx for replying.
It still times out when I use either of those alternatives.
can you tell what exactly the script is timing out on - i.e. are you 
sure its the call to the DB? you SQL _may_ not be the most efficient way 
of doing it (not that I know or anything) but I can tell you that I have 
a query on a production site which involves 16 JOINS and that works fine 
[I can here you laughing in the bach there ;-)] - actually it had 33 
JOINS but there is a hard limit to the number of joins per statement in 
the version of MySQL the site uses so I had to split the query into 2!

also have you tried running the complete query/queries directly in a 
MySQL console? i.e. remove PHP from the equation to determine if the 
problem is actually the SQL. please tell us whether the statements work 
ok when you run them directly.

I've tried changing all the JOINs around and nothing works.
Post the table deinfitions to the list + a recap on what you are trying 
to get as a result.

I thought maybe there's a logic problem going on?
some kind of problem anyway ;-)
snip
SELECT b.fldName, b.fldEmail, b.fldCountryCode, d.fldCode as FCode, 
b.fldMobile, a.fldTime as Time, c.fldUsername FROM 
tblSubscribersChoices a INNER JOIN tblUser c on 
a.fldChoice=c.fldClientID LEFT JOIN tblSubscribers b on a.fldClientID 
= b.fldID LEFT JOIN tc_countries d on b.fldCountryCode = d.fldCode 
ORDER BY `c`.`fldUsername` ASC
in the orderby clause you apply backticks to the table alias 'c', which 
you don't do anywhere else. its a long shot but try removing those 
backticks.

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


Re: [PHP-DB] LEFT joins

2005-01-12 Thread Jochem Maas
Han wrote:
Oh yes, sorry, not used to the reply-all.
most of us get hammered by that one once in a while!
read on the the interesting bit...
I've pasted it directly into the MYSQL console as just sql and this is 
where I discovered my problem.

My code is : --
SELECT b.fldName, b.fldEmail, b.fldCountryCode, b.fldMobile, a.fldTime 
as Time, c.fldUsername FROM tblSubscribersChoices a INNER JOIN tblUser c 
on a.fldChoice=c.fldClientID LEFT JOIN tblSubscribers b on a.fldClientID 
= b.fldID ORDER BY `c`.`fldUsername` ASC

Now this works fine.
But, I'm trying to tally the country code with it's actual name (which 
is held in tc_countries). So I thought if I add another LEFT JOIN at the 
end of the query : --

SELECT b.fldName, b.fldEmail, b.fldCountryCode, d.fldCode as FCode, 
b.fldMobile, a.fldTime as Time, c.fldUsername FROM tblSubscribersChoices 
a INNER JOIN tblUser c on a.fldChoice=c.fldClientID LEFT JOIN 
tblSubscribers b on a.fldClientID = b.fldID LEFT JOIN tc_countries d on 
lets look just at this last little bit of the statement:
b.fldCountryCode = d.fldCode ORDER BY `c`.`fldUsername` ASC
try changing this to:
d.fldCode = b.fldCountryCode ORDER BY c.fldUsername ASC
(I removed the backticks too, as you don't use them in the rest of your 
query, and that was irritating the aethetic monster within me ;-)

Actually looking at your complete statement you _seem_ to have got all 
the JOINS backwards (I'm no SQL guru so I may be totally wrong here, 
besides which I don't know the DB-schema your using), does this work:

SELECT b.fldName,
   b.fldEmail,
   b.fldCountryCode,
   d.fldCode as FCode,
   b.fldMobile,
   a.fldTime as Time,
   c.fldUsername
FROM tblSubscribersChoices a
LEFT JOIN tblUser c ON c.fldClientID = a.fldChoice
LEFT JOIN tblSubscribers b ON b.fldID = a.fldClientID
LEFT JOIN tc_countries d ON d.fldCode = b.fldCountryCode
ORDER BY c.fldUsername ASC
and if that works but doesn't give you repeat records try adding the
DISTINCT keyword after SELECT.
snip



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


Re: [PHP-DB] LEFT joins

2005-01-12 Thread Jochem Maas
Han wrote:
Hmm,
still no luck. Thanks for the help. I think I'll have to break the 
you mean that it still times out? crashes mysql?
maybe the table (tc_countries) is corrupt? try doing a repair.
select up into 2 selects and throw the results of the first into arrays.
Didn't want to do it like that, but it's gonna be quicker now.
if at first you don't succeed... hack ;-)
snip
try removing the ORDER BY Clause:
SELECT b.fldName,
   b.fldEmail,
   b.fldCountryCode,
   d.fldCode as FCode,
   b.fldMobile,
   a.fldTime as Time,
   c.fldUsername
FROM tblSubscribersChoices a
LEFT JOIN tblUser c ON c.fldClientID = a.fldChoice
LEFT JOIN tblSubscribers b ON b.fldID = a.fldClientID
LEFT JOIN tc_countries d ON d.fldCode = b.fldCountryCode
ORDER BY c.fldUsername ASC

OR
SELECT b.fldName,
b.fldEmail,
b.fldCountryCode,
d.fldCode as FCode,
b.fldMobile,
a.fldTime as Time,
c.fldUsername as Username
FROM tblSubscribersChoices a
LEFT JOIN tblUser c ON c.fldClientID = a.fldChoice
LEFT JOIN tblSubscribers b ON b.fldID = a.fldClientID
LEFT JOIN tc_countries d ON d.fldCode = b.fldCountryCode
ORDER BY Username ASC
and if that works but doesn't give you repeat records try adding the
DISTINCT keyword after SELECT.
snip
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] Slow Query

2005-01-12 Thread Jochem Maas
Wendell Frohwein wrote:
snip
So I rewrote my script to do the follow:
The client submits a property for an appraisal.
Based on the appraisal type and property zip code, It does a radius
search of 2 miles from the property zip. If no matches are found, it
does a 5 mile radius search. For every zip code returned by each radius
search, It searches the database for agents / appraisers with the zip
code in question (zip codes from radius search) in there coverage.
This is the most stressful part I am assuming. This works fine for 1 -
10 orders. But when I import 30 or more, the script pretty much hangs as
well as mysql. I have to kill mysql with signal 9, start mysql it up
again. Then all is back to normal. I would paste the code in here but it
is really long and complicated.
snip
there was/is a thread going on at php-generals regarding 
zipcode-long/lat issues (you may have seen it).

one of the things that came up is doing the joins on the tables in 
question (and/or doin the maths) is heavy work. I would imagine that the 
results for a given calculation (i.e. get postcodes with certain radius) 
 stays the same, if they do then it may be an idea to do the 
calculation before hand and store the results in a way that its very 
fast to access e.g. writing out PHP arrays into files for later 
inclusion as required (possibly because new postcodes are occasionally 
added you may want that to trigger a recalculation - e.g. when a new 
postcode is added do the calculation then for all postcodes found do a 
recalculation for those as well!).

so...It doesn't sound like you can get round the ammount of processing 
that needs to be done but maybe you can do it 'offline' and store the 
results for quick access when you need it?

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


Re: [PHP-DB] Assistance on Query

2005-01-16 Thread Jochem Maas
Shannon Doyle wrote:
Hi People,
I would like some assistance on the following scenario.
I have to pull out all records for a particular userid (easy enough) and
then only show those entries where the follwing occurs.
These records from the table will contain either an entry in the
services_type field or the non_services_type field. What I need to do is
show only those where the number of consecutive records that contain an
entry in the non_services_type field is greater than or equal to 3
so example:-
record 1 contains an entry in non_services_type
record 2 contains an entry in services_type
record 3 contains an entry in non_services_type
record 4 contains an entry in non_services_type
record 5 contains an entry in non_services_type
record 6 contains an entry in services_type
so I would need to display records 3,4,5 only
Can anyone assist me with this?
Could you explain what the logic behind doing this is. i.e. Why?
(it might help to understand the problem, and possibly give a solution 
that does not rely on 'consecutiveness')

I'm guessing you are using MySQL which is a relational DB, that means 
the order of records stored is essentially abstracted from the DB user, 
for instance using an ORDER BY clause will change the order of the 
result and therefore the 'consectiveness' of the values.

It looks as if you will need to post-process the result set in PHP to 
get what you want, alternatively your DB may support stored procedures 
which could be an alternative (but harder to do than to do it in PHP) 
i.e. the stored procedure works out the correct rows and then outputs 
the result when you something like:

SELECT * FROM getConsecServiceRows( 3 )
rgds,
Jochem
Cheers,
Shannon
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] Assistance on Query

2005-01-16 Thread Jochem Maas
Shannon Doyle wrote:
Hi Jochem,
My apologies, when I typed consecutive, I meant by date. Basically the query
is for a report. The client wants to be able to see when there have been 3
or more entries of non_services_type between services_type entries, and then
display these entries.
I am using MySQL and would Order the entries by date.
I hope that clears things up a little. 
yeah! I can't think how to do that offhand in SQL but in php it would go 
a little like this...(I'm assuming an array of results is being passed - 
where each item in the array is an object.):

function filter3ConsecutiveNST($rows)
{
$output = $tmp = array();
$cNSTcount = 0;
foreach ($rows as $row) {
if ($row-type == 'non_service_type') {
$cNSTcount++;
if ($cNSTcount == 3) {
$output =+ $tmp;
$output[] = $row;
$tmp = array(); 
} else if ($cNSTcount  3) {
$output[] = $row;   
} else {
$tmp[] = $row;  
}   
} else {
$tmp = array();
$cNSTCount = 0; 
}
}
return $output;
}
hope that give you an idea.
- Shannon
-Original Message-
From: Jochem Maas [mailto:[EMAIL PROTECTED] 
Sent: Monday, January 17, 2005 1:37 AM
To: Shannon Doyle
Cc: php-db@lists.php.net
Subject: Re: [PHP-DB] Assistance on Query

Shannon Doyle wrote:
Hi People,
I would like some assistance on the following scenario.
I have to pull out all records for a particular userid (easy enough) and
then only show those entries where the follwing occurs.
These records from the table will contain either an entry in the
services_type field or the non_services_type field. What I need to do is
show only those where the number of consecutive records that contain an
entry in the non_services_type field is greater than or equal to 3
so example:-
record 1 contains an entry in non_services_type
record 2 contains an entry in services_type
record 3 contains an entry in non_services_type
record 4 contains an entry in non_services_type
record 5 contains an entry in non_services_type
record 6 contains an entry in services_type
so I would need to display records 3,4,5 only
Can anyone assist me with this?

Could you explain what the logic behind doing this is. i.e. Why?
(it might help to understand the problem, and possibly give a solution 
that does not rely on 'consecutiveness')

I'm guessing you are using MySQL which is a relational DB, that means 
the order of records stored is essentially abstracted from the DB user, 
for instance using an ORDER BY clause will change the order of the 
result and therefore the 'consectiveness' of the values.

It looks as if you will need to post-process the result set in PHP to 
get what you want, alternatively your DB may support stored procedures 
which could be an alternative (but harder to do than to do it in PHP) 
i.e. the stored procedure works out the correct rows and then outputs 
the result when you something like:

SELECT * FROM getConsecServiceRows( 3 )
rgds,
Jochem

Cheers,
Shannon

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


Re: [PHP-DB] PHP 5.0.3 and Oracle9i on Windows 2000/Apache

2005-01-17 Thread Jochem Maas
Chaun Keating wrote:
I am having trouble logging onto Oracle via PHP on a Windows 2000 machine.
I keep getting the error:
Fatal error: Call to undefined function OCILogon() in C:\Program
Files\Apache Group\Apache2\htdocs\oraconnect.php on line 15
I seem to have everything set up correctly.  I am running an Oracle 9i
client and have set up the php.ini file with extension=php_oci8.dll
uncommented, left ;extension=php_oracle.dll commented. (Although I have
tried various combinations of these two.  Also I have set the extension_dir
= C:\Program Files\PHP\ext correctly and noted that php_oci8.dll and
php_oracle.dll exist there.
Now here is where it gets really weird and I could use some help:
It works fine from the command line:
possibly the cli version of php is using a different ini file than the
apache2 module/cgi. also you made need to restart apache in order to 
reread the php.ini file.

with regard to putenv() - you may be suffering from safe_mode being on.
also, (I don't know this!), if putenv is setting env vars whose scope is 
server-process wide then concurrent scripts _maybe_ messing each other 
up: e.g.  request1 starts and does some putenv()s, request2 does the 
same a fraction later, request1 finishes and resets stuff done by 
putenv(), request2 trys to connect...which fails because the env vars 
are empty.

I type php oraconnect.php for the following code:
?php
//putenv(ORACLE_SID=TESTDB);
//putenv(ORACLE_HOME=C:/oracle/ora92);
//putenv(TNS_ADMIN=C:/oracle/ora92/network/admin);
$username = SCOTT;
$passwd = TIGER;
//$db=(DESCRIPTION=
 //  (ADDRESS_LIST=
  //   (ADDRESS=(PROTOCOL=TCP)
   //(HOST=orahostname1)(PORT=1621)
// )
 //  )
  //   (CONNECT_DATA=(SERVICE_NAME=TESTDB))
   //  );
$conn = OCILogon(SCOTT,TIGER,TESTDB);
if (!$conn)
{
   echo Connection failed;
   echo Error Message: [ . OCIError($conn) . ];
   exit;
}
else
{
   echo Connected!;
}
?
It works either way with the env_variables in the script or with them
commented out from the command line.  I just can't get it to work from the
browser.
Can anyone out there help me with this one?  I have some experience with
Oracle, Perl, and a little Java but not so much with PHP.
Thanks.
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] mysql - image storing

2005-01-18 Thread Jochem Maas
Martin Norland wrote:
Joseph Crawford wrote:
Jason, can you explain why stripslashes should not be used on data
taken from the db? when you store data in the db i thought it was good
practice to addslashes, when you retrieve from the db, you will need
to use stripslashes to remove the extra \

The slashes are added for the database, not to be stored with the data.
for e.g. - to store:  I've just eaten.
you do: INSERT INTO status (hunger) values ('I\'ve just eaten.');
I was always under the impression that single quotes (assuming you are 
delineating you args with single quotes) should (officially) be escaped 
with another single quote - although backslash also works:

INSERT INTO status (hunger) values ('I''ve just eaten.');
...alot of really old code of mine is full of stuff like:
$var = str_replace(','',$var);
but maybe that just MTAM(tm) working for me - (thats a reference to a 
bit of humour from another thread btw - MTAM is not a technology :-)

which stores: I've just eaten.
It's not good practice - it's required (if you're not using a mechanism 
that already handles this - such as the latest mysqli bind functions) - 
otherwise the query is invalid.
nice to learn that mysqli is getting it 'right' :-) [makes mental note 
to look into it!]

You may be thinking of running 'htmlentities' when retrieving data - 
which is necessary in some cases, depending on where you're using it 
(most notably - in html where you don't want html output).

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


Re: [PHP-DB] mysql - image storing

2005-01-18 Thread Jochem Maas
Joseph Crawford wrote:
Jason, can you explain why stripslashes should not be used on data
taken from the db? when you store data in the db i thought it was good
although 'slashing' text works pretty much all of the time (possibly the 
guys using exotic encodings all day will say different :-) but the data 
you are storing in the DB is binary - stripping and slashing will 
probably do weird things to the data:

try creating some image data and run it thru add_slashes() and 
stripslashes() and compare the output of each with the original.

practice to addslashes, when you retrieve from the db, you will need
why is it good practice? (anyone)? sounds like pure overhead to me.
you could look up 'magic quotes' in relation to this, its often where 
the trouble starts!

on a side note:
-
me I use the ibase/firebird php extension which has parameterized 
queries - so I can say goodbye to mysql_escape_arg() (or whatever the 
damn function is called) and having to hand craft lots of arg checks -
but alas you may not have access to a firebird DB.


to use stripslashes to remove the extra \

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


Re: [PHP-DB] mysql - image storing

2005-01-18 Thread Jochem Maas
Simon Rees wrote:
On Tuesday 18 January 2005 19:18, Jochem Maas wrote:
I was always under the impression that single quotes (assuming you are
delineating you args with single quotes) should (officially) be escaped
with another single quote - although backslash also works:

I think it depends on the database that you are using. Oracle and MS-SQL 
both require quotes to be escaped with another quote, MySQL uses 
backslashes.
I seem to recall that two quotes is the standard...

Of course it is even better to use bind vars and then you don't need to 
escape the quotes (or worry about sql injection attacks)...
did I mention I have been using firebird and the php-extension for the 
last year and a half ;-)

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


Re: [PHP-DB] mysql - image storing

2005-01-18 Thread Jochem Maas
Martin Norland wrote:
Jochem Maas wrote:
I was always under the impression that single quotes (assuming you are 
delineating you args with single quotes) should (officially) be 
escaped with another single quote - although backslash also works:

INSERT INTO status (hunger) values ('I''ve just eaten.');
...alot of really old code of mine is full of stuff like:
$var = str_replace(','',$var);
but maybe that just MTAM(tm) working for me - (thats a reference to a 
bit of humour from another thread btw - MTAM is not a technology :-)

AFAIK - for Sybase and CSV yes, otherwise no (in general).  Maybe it's a 
compatibility option?  Still, there are perfectly valid reasons to have 
multiple ''s.  (why, there's one now - sort of...)
ok - cheers, just for the record If I wanted to insert your sentence:
'Still, there are perfectly valid reasons to have multiple s'
:-)
Cheers,
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] LEFT joins

2005-01-20 Thread Jochem Maas



OR
SELECT b.fldName,
b.fldEmail,
b.fldCountryCode,
d.fldCode as FCode,
b.fldMobile,
a.fldTime as Time,
c.fldUsername as Username
FROM tblSubscribersChoices a
LEFT JOIN tblUser c ON c.fldClientID = a.fldChoice
LEFT JOIN tblSubscribers b ON b.fldID = a.fldClientID
LEFT JOIN tc_countries d ON d.fldCode = b.fldCountryCode
ORDER BY Username ASC
and if that works but doesn't give you repeat records try adding the
DISTINCT keyword after SELECT.
snip
Why are you so intrested in LEFT JOIN? I cn't help much since i don't 
I'm not but his original query used JIONs and a LEFT JOIN is (IMHO) the 
easiest to understand. I didn't have the presence of mind to rewrite the 
query using a simple WHERE clause - hope your tip helps him.

btw: can anyone say if the LEFT JOIN or the alternative WHERE statement 
(in general?) is faster?

know the schema of the db and i can't see clear the meaning of the 
tables in the query.
Anyway try this:
SQL
SELECT b.fldName,
 b.fldEmail,
 b.fldCountryCode,
 d.fldCode as FCode,
 b.fldMobile,
 a.fldTime as Time,
 c.fldUsername as Username
 FROM tblSubscribersChoices a, tblUser c, tblSubscribers b,
tc_countries d
 WHERE c.fldClientID = a.fldChoice AND b.fldID = a.fldClientID AND
d.fldCode = b.fldCountryCode
 ORDER BY Username ASC
/SQL
Bye

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


Re: [PHP-DB] LEFT joins

2005-01-20 Thread Jochem Maas
Martin Norland wrote:
Jochem Maas wrote:
I'm not but his original query used JIONs and a LEFT JOIN is (IMHO) 
the easiest to understand. I didn't have the presence of mind to 
rewrite the query using a simple WHERE clause - hope your tip helps him.

btw: can anyone say if the LEFT JOIN or the alternative WHERE 
statement (in general?) is faster?

I can't speak to the speed, although since JOINs (can) do more than 
simple matching, I'd say the where condition may turn out a little 
better (after crossing fingers that mysql will use the proper indices in 
all cases).

An example of something I can't think of how to write into a where 
clause (easily, at least):
from http://dev.mysql.com/doc/mysql/en/JOIN.html :

If there is no matching record for the right table in the ON or USING 
part in a LEFT JOIN, a row with all columns set to NULL is used for the 
right table. You can use this fact to find records in a table that have 
no counterpart in another table:
mysql SELECT table1.* FROM table1
-LEFT JOIN table2 ON table1.id=table2.id
-WHERE table2.id IS NULL;

I remember reading that now - last time I did major surgery with MySQL - 
it had to do with loads of IFNULL and CONCAT statements - thats where 
the specifics of the LEFT JOINS (null values produced) came in (must 
have stuck in my head).

The 'explain' syntax can give you some idea of this, as well as help you 
in optimizing indices and queries.
never did quite understand the explain output. :-)
http://dev.mysql.com/doc/mysql/en/EXPLAIN.html
Cheers,
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] LEFT joins

2005-01-20 Thread Jochem Maas
Basile Francesco wrote:
In general, you should not worry about faster query sintax, since mysql 
should (but i'm not sure) have an optimizer inside wich translate your 
sintax query in a better efficient one.
Anyway, the where statement is perfectly equal to the join operator, 
it is called, in general, theta-join and in this case it is called 
equi-join (equi...because in the where statement you only compare 
attributes by the '=' operator).
The only reason you want to use the left-join, which is a particular 
case for a general outer-join, is if you want to fill your result with 
NULL values rather than an empty records.

cheers for that :-)
I remembered something along those lines but the specifics of JOINing 
always leak from my head. :-)

Jochem Maas ha scritto:

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


Re: [PHP-DB] Re: Cannot load MySQL extension (mysql.so issues)

2005-01-21 Thread Jochem Maas
franciccio wrote:
Eve Atley ha scritto:
Platform: Redhat Linux Enterprise WS 3
PHP installed: 4.3.2
MySQL installed: 4.0.21
Apache installed: 2.0.46
When setting up PhpMyAdmin today, I got the error:
Cannot load mysql extension,
Please check PHP configuration
My phpinfo() shows:
'with-mysql=shared,/usr' (yes, the comma is not a mistake)
- This looks like a glitch; should I fix, and if so where?
Mysql.so was found in:
is the file _actually_ called 'Mysql.so'
the capital M would see to it that the extension is not found.
sorry I can't help you any further.
/usr/lib/php4/
My php.ini has been editted to read:
extension=mysql.so
...and I also tried:
extension=/usr/lib/php4/mysql.so
Any clues on remedying this problem, without upgrading MySQL? I have read
the problem is solved by installing a PHP-MySQL package, but when I
attempted to do so via up2date, I was notified that a dependency was
required for a MySQL-client. But Mysql is already installed and running.
Any clues out there?
Thanks,
Eve
Wrong thread and group.
Bye
normally I would agree with franciccio's remark (and I can't be too hard 
on him either cos he gave me a good explaination on JOIN stuff just 
yesterday!) BUT women deverse preferential treatment in this 
environment. here is why:

rant
a, IT is a 'male' (read: autistic ;-) social culture - why expect women 
to fit right in when they have different (read: higher ;-) social skills 
(in general).
b, there are not enough of them in IT let alone the PHP world.
c, they might be good looking and live round the corner from you ;-).

the more women in IT the better it is for all of us - it gives us more 
social power as a group and makes us more balanced + you'll often find 
women have novel/new ways of looking at problems that a male mindset is 
less likely to consider.

women/girls deserve a little more leaway when entering this little 
world. if only because men have been jacking them around for the last 
5000 years - which has only brought us war  religion ;-)
/rant 	

oh hang on - Eve did pretty much everything right in writing up her 
question to the list (setup details, context, explaination of things 
tried, consiseness etc etc) the only thing she may have done wrong is in 
the choice of list (possible php-general or php-install could have been 
a better choice). so thats another reason to cut her some slack.


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


Re: [PHP-DB] Re: Cannot load MySQL extension (mysql.so issues)

2005-01-21 Thread Jochem Maas
Eve Atley wrote:
women/girls deserve a little more leaway when entering this little 
world. if only because men have been jacking them around for the last 
5000 years - which has only brought us war  religion ;-)

ROTFL!! Too funny. :) 

thanks. :-)
I got the issue somewhat resolved. I was being a slacker and wanted to
administer MySQL with phpmyadmin, and I thought it would be an easy fix, but
your not using MySQL in combination with php (other than the attempt to 
run phpmyadmin)?

I opted for the command line eventually. While phpmyadmin still doesn't work
despite mysql.so existing on my system (Mysql.so was Outlook insisting on
proper capitalization), I got everything else working, in this particular
case MySQL, via the command line. 
You said your using RedHat, do you have a choice in that?, are you okay 
with linux? Give SuSE a shot - as a distro is much better, german 
engineering and that and its got the backing, now that Novell has taken 
over shop (Novell of IT excellence, as opposed the marketing finesse of 
RedHat). for a little more extreme try Debian - if you can handle using 
a bash shell you will find it joyful, its start off with `aptget`, a few 
configures, make, make installs, zoom.

Im no expert but I can setup servers ok, I just FTFM and it takes me a 
while :-) and lately Ive been setting up a fairly complex php 
webshop/site/cms type thing for a company that insists on redhat server 
bla bla bla edition - and its a nightmare - try setting up 
php5/firebird1.5/apache argh - well the guy that set it up said argh 
and next to me he's an honest to god wizard! they have it set so that 
technically you have to login to a website of redhat and the
site logs into your machine and finds out whats installed, which it then 
reports back to you on the site. WTF!!! its pure madness. a man 
obviously thought this up. straight up.

in my world:
1. RedHat - like treading in something brown and steaming.
2. SuSE   - like driving in a Mercedes, but not always a brandnew one.
3. Debian - spaceship (or more precisely: The Tardis).
which would you choose?
just MHO
And I posted here, assuming it was linked between PHP and MySQL, being that
phpmyadmin is written in PHP and works off MySQL. Does not appear to be the
case however!
I didn't quite get it either!
Thanks,
Eve
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] Given only one mySQL user account by Host Company

2005-01-23 Thread Jochem Maas
Shay definitely has bad hosting.
the guy wants a seperate mysql user with readonly privileges on his DB which
is good practice. only ...
his hostingco. has given him a single DB and a single user a/c. no doubt they 
manage
their system via a webinterface - when every they add a customer, they check the
box marked add MySQL DB to hosting package and click go.
I bet that Shay does not have access to the MySQL system tables - like he said,
the user a/c he has been given any grant privileges (at least that what I think 
he meant)

Bastien Koert wrote:
What admin tools do you have for the db? PhpMyAdmin? something else? 
Many of those can be used to create additional user accounts with more 
limited restricitions.

Bastien
From: Shay [EMAIL PROTECTED]
Reply-To: Shay [EMAIL PROTECTED]
To: php-db@lists.php.net
Subject: [PHP-DB] Given only one mySQL user account by Host Company
Date: Sun, 23 Jan 2005 03:03:26 -0700
My hosting company gave me one database and one root user account, and I
have no access for priviliges at all. So as far as I can tell, the 
only way
for me to connect to the database on my site is to do a
mysql_connect(host, user, pass), where the user and pass are the 
ones
for this one super account.

Is this a major security concern or what? Is there a way around this, 
or a
way to minimize security problems? I've emailed them about this, and they
act like they have no clue what I'm talking about:

I'm not trying to hide files or directories, I'm talking about when I 
use
PHP and make a connection to the database using mysql_connect(host,
user, pass). This script is what is in my webpages that connects 
to the
DB and retrieves data to print for users. Is there an anonymous 
account to
use for retrieving data, or can I make one?


Then the program or script you are using should have means
for your users to access permitted areas. And there is no
anonymous account, there is only your own account Db
Now. Hosting company provide your site with tool for you to use your
own programs and it's up to you which programs and how you use them.
Our job is to make sure the tool is working. Other than that, we do not
provide support for scripts and the programs you are using.
If you having problems to use some programs then you need to get
in touch with developers and find what need to be done and how.
boilerplate idiots.
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

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


Re: [PHP-DB] GROUP BY? Urgent help needed with selection list

2005-01-23 Thread Jochem Maas
Chris Payne wrote:
Hi there,
The problem is, the database is imported from a huge properties database and
can only be imported in the format from the central database of estate
agents, so I can't reformat it in the tables itself.
Each table has the same fields, but one is for condo's, one is for
you need UNION - use of the UNION clause assumes 2 things:
1. all the tables in question do indeed have identical columns
2. the UNION clause is supported by the version of your DB software
having said that if you are importing the data and each 'table' is of
the same format why not just import each file/table into 1 table in your DB?

residential etc . however, the client need to be able to do a search all
tables query, and bring the results up as though you are only search 1
table.  I've never searched multiple tables before without a relative ID,
what I need is to search all of them as though it is just searching 1, so I
don't think multiple queries would work, hence why I'm trying to do it all
in a single query.
Chris

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


Re: [PHP-DB] Auto Responses?

2005-01-24 Thread Jochem Maas
Nigel Jones wrote:
Problems guys...
Emails don't actually come from [EMAIL PROTECTED] they are sent to
[EMAIL PROTECTED] and then sent like it was an email from the sender to
x subscriber...
Really you should be suggesting that the subjects be used in the
event/filter things.
Autoresponders DO have their uses (business people, as long as they
aren't using their business account for lists) to ones that are, sign
up for a free hotmail/yahoo/gmail/* webmail account and get php list
stuff sent there instead (there are many people on this list with free
gmail invites if you still need them).  That or ask your network
I don't use autoresponders - If I ever go away, I either:
a, take a laptop and check for urgent stuff.
b, send important clients/colleagues an email saying when I'll be back -
which takes roughly the same time as setting up the autoresponder and has
the added bonus that you don't have to remember to turn off the auto-responder
when you get back ;-)
having said that I'd love a gmail invite - I wanna dig into their madhatter
javascript used in the clientside interface and learn a few tricks. so
if anyone has a spare ...?
admin/postmaster/yourself (if your that lucky) to setup another
account for you
...
This is getting way off topic. I don't use any autoresponders on my mail
client so I can't give any advice there (but I'm sure google can). I only use
autoresponders on my mailserver. These look at the headers of the incoming
mail to determine whether an autoresponse is appropriate. The autoresponders
will also limit the number of autoresponses so that if eg your friend sends
you 100 mails, they will not be told 100 times that you're having a whale of
a time in Hawaii, it will only frustrate them and foment envy :).

BTW: Jason what server side autoresponder are you using?
...
rgds,
Jochem
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] Auto Responses?

2005-01-24 Thread Jochem Maas
Martin Norland wrote:
Jochem Maas wrote:
Nigel Jones wrote:
Problems guys...
Emails don't actually come from [EMAIL PROTECTED] they are sent to
[EMAIL PROTECTED] and then sent like it was an email from the sender to
x subscriber...
Really you should be suggesting that the subjects be used in the
event/filter things.
On that note - why is it that vacation autoreplies get through to this 
list, but if you dare to speak the dreaded o f f - t o p i c or [ O - T 
] keywords your mail doesn't get through?
its a mad world. :-)

I don't use autoresponders - If I ever go away, I either:
a, take a laptop and check for urgent stuff.
b, send important clients/colleagues an email saying when I'll be back -
which takes roughly the same time as setting up the autoresponder and has
the added bonus that you don't have to remember to turn off the 
auto-responder
when you get back ;-)
Assuming you have this luxury.  A bigger question is, how often are 'we' 
(e.g. techies) in positions where we're away for so long, and so 
immediately available to clients - but those clients don't know our 
schedule?  If I'm so 'in bed' with a client that they expect 
instantaneous turnaround, I would just warn them directly - maybe my 
experiences are unique.  I just don't service a lot of people at a 
time - I would think anyone who does either keeps communication open or 
has others servicing them also.
good point, I indeed have the luxury of having a limited no. of (relatively
important) clients, this makes things easy.

having said that I'd love a gmail invite - I wanna dig into their 
madhatter
javascript used in the clientside interface and learn a few tricks. so
if anyone has a spare ...?
Martin delivered the goods! many thanks to him, and anyone else who would
have sent one (if Martin hadn't gotten there first :-) )
rgds,
Jochem

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


Re: [PHP-DB] Out of the Office

2005-01-24 Thread Jochem Maas
Hutchins, Richard wrote:
Agh!
You have GOT to be friggin' kidding me!
chill.
These autoresponders and the whole discussion of how they work or don't work
are just cluttering up this list.
true.
Please just everybody do everybody else a favor and _think_ before you
use/configure your autoresponder and take the whole other discussion (while
one of those is definitely not going to happen in the near future :-)
I'm sure it has merit) off list.
who is it that is supposed to admin this list? the person responsible 
doesn't
seem to have the time (and/or the problems are not critical enough to warrant
attention). is there anybody on this list capable of doing the admin? would they
have some time to do it? and if so is there any possibility of giving such
person karma to do some clean up etc?
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] Really Stuck!

2005-01-25 Thread Jochem Maas
Ben wrote:
Hello all,
As a beginner I have been trying to send two attachments from my HTML form.
the code you posted has no baring on DB stuff. so probably you question was
better aimed at php-generals, anyways
Below is the code I have been using. The problem is, I seem to only be able
to send one or the other, when I send both, although they go through, the
text I want displayed tags 6110 etc, is also sent as an attachment. Any help
would be greatly appreciated as I have a huge headache!
not surprised, anyway save you self more headache - get phpmailer instead, 
some smart
guy(s) has done all the work for you :-)
phpmailer.sourceforge.net

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


Re: [PHP-DB] Double Inserts

2005-01-25 Thread Jochem Maas
Bastien Koert wrote:
post code...can't read minds, you know
;-)
cant-help-myself style=no-disrespect-to: bastien;
well yes, you have to understand Bastien is only an apprentice has not
yet been initiated into the inner mind-readers circle.
I on the other hand can tell you with utmost certainty that the solution is 42
/cant-help-myself
give us code so we can get our 'helpers' fix :-)
Bastien
From: [EMAIL PROTECTED] (PHPDiscuss - PHP Newsgroups and mailing 
lists)
To: php-db@lists.php.net
Subject: [PHP-DB] Double Inserts
Date: 25 Jan 2005 17:32:28 -

Hi, I am new to the mailing list and to PHP / MySQL. I am facing an
unususal problem. I am trying to insert some data into MySQL DB through
via Web. The code is executed OK - no errors but the same record gets
inserted TWICE. I have checked the code and simplified it as much as
possible and tried test scripts with same results. I have also tried
statements to echo messages to ensure the code is not executed twice.
It happens with IE as wells as Mozilla so I don't think it is a browser
issue. The only clue is that it does not seem to happen on a slower
machine (Laptop). The configurations, versions etc are identical - Apache
2.0.49, MySQL 4.1.6-gamma-nt, PHP 5.0.2
Has anyone faced this and found a solution? Please help.
Shri
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

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


Re: [PHP-DB] Double Inserts

2005-01-25 Thread Jochem Maas
Martin Norland wrote:
Bastien Koert wrote:
I am but your padawan
brilliant.
Bastien
[snip]
From: Jochem Maas [EMAIL PROTECTED]
cant-help-myself style=no-disrespect-to: bastien;
well yes, you have to understand Bastien is only an apprentice has not
yet been initiated into the inner mind-readers circle.
I on the other hand can tell you with utmost certainty that the 
solution is 42
/cant-help-myself
[snip]
In all fairness, I'd say Bastien is a frood who really knows where his 
towel is[1].  He's surely finishing up his apprenticeship.

1 http://hhgproject.org/entries/towel.html
ditto.
:-)
Cheers,
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] IIS, PHP, and session data

2005-01-25 Thread Jochem Maas
Perry, Matthew (Fire Marshal's Office) wrote:
I am having trouble with my session data on Microsoft IIS.
Here is a little background of the problem:
 

1)   I am not personally in control of our web server.  Our IT
department manages it.  They have IIS running on their sever and use MS SQL
Server, but they have allowed me to use PHP instead of ASP.
2)   I have Apache running on a local web server in our office (not the
IT department).  It accesses the SQL Server database remotely.  I have
register_global turned OFF and use the following code on each page: 

session_start();
session_register('logged_in');
session_register('username');
have you tried using the $_SESSION superglobal instead?
you dont state the versions of php btw.
...
Thank you for your time,
Matthew Perry

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


Re: [PHP-DB] works on command line, not on server

2005-01-26 Thread Jochem Maas
The Disguised Jedi wrote:
try users@httpd.apache.org list
On Tue, 25 Jan 2005 14:21:25 -0800, [EMAIL PROTECTED] [EMAIL PROTECTED] 
wrote:
I have a new installation of php on an existing apache 2 server, and
something strange is happening.  The file 'test.php' works and connects to
the database when run through the command line, but when run from the web
server (http://server/test.php) produces a segmentation fault:
   child pid 29056 exit signal Segmentation fault
segmentation faults are a built in feature of the PHP/Apache2 setup 
whenever you don't
use the PREFORK Apache2 worker module - I know barely enough to know this - 
this is due to
threading (which is not supported with ?most? php extension - not sure if php 
itself
has this problem also).
Anyway bottom line switch to PREFORK worker module if your not already using it,
alternatively you could try to get a stable threaded setup going but before 
you
embark I'd like to paraphrase a higher PHP authority, Rasmus Leidorf
(they don't get any higher actually) speaking in relation to using
a threaded Apache2 worker module:
Your in unchartered territory, good luck.
and
Nobody knows.
php itself does work, and a file with only phpinfo() in it runs fine on both
the server and the command line.  Has anyone seen anything like this before?
Any ideas?
?php
$link = mysql_connect(localhost, user, pass)
   or die(Could not connect);
mysql_select_db(disorder) or die(Could not select database);
print hello;
also you may need/wish to try the newer mysqli_* extension which is
geared to the latest versions of MySQL.
?
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



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


[PHP-DB] firebird - equivalent of stristr() in Stored Procedure.

2005-01-26 Thread Jochem Maas
hi Guys,
I'm using Firebird 1.5 with PHP5.
I have a problem where by I am trying to do the equivelant of:
$a = 'A';
$b = 'AG';
if (stristr($b, $a)) {
// do something.
}
Inside a Stored procedure, where $a and $b are both input variables
to the stored procedure.
The Interbase Lang Ref (PDF) doesn't help
me here - I've tried all sorts of forms of syntax using CONTAINS and LIKE
but it all gives syntax errors... (which didn't surprise me!)
Then I thought that I could used Ard Biesheuvels php_ibase_udf UDF lib for
firebird,  php_ibase_udf.c is in the php cvs (somewhere); this lib allows access
to php functions defined in your calling scripts. at any rate I get BLR type 
errors
when I tried to use the UDFs (btw googling php_ibase_udf.c doesn't return a 
lot, but
you will definitely find one email mentioning the BLR error!!). Actually I have 
tried
setting up this UDF lib on 3 different servers (all fbird1.5/php5 - different 
minor versions)
with out any luck.
does anyone have a clue as to how do the equivalent of the PHP above inside
a firebird stored procedure? or possibly can point out so good 
literature/examples
(all the good firebird stuff seems to be in russian) on/of 'advanced' stored
procedures.
alternatively is there anyone out there that has gotten the php_ibase_udf UDF 
lib
to work (Lester Caine have you tried it yet?, I ask you specifically because 
your
name often pops up on php lists in relation to firebird :-).
before any says: why not ask the developer - we'll his is an aquaintance of 
mine,
I have his mobile number and I have asked him!, its just a case of he has _no_ 
time
(due to dissitation/research  commitments) to dig into the problem and
I know that he will help when he gets some free time again, but for now I'm on 
mine own.
hope somebody can give me a clue :-),
thanks and regards,
Jochem
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] firebird - equivalent of stristr() in Stored Procedure.

2005-01-26 Thread Jochem Maas
Jochem Maas wrote:
hi Guys,

hope somebody can give me a clue :-),
well about 5 mins after I posted I managed to find a solution thanks to
a man named Ivan Prenosil (who by all accounts knows where his firebird towel 
is ;-)
http://www.volny.cz/iprenosil/interbase/ip_ib_code_string.htm
(the stored procedure named 'Pos' on that page was basically what I was looking 
for.)
btw - if somebody at google decided to throw all the Mozilla related references
to the word 'firebird' out of the F** indexes I wouldn't loose any sleep 
over it.
thanks and regards,
Jochem
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] works on command line, not on server

2005-01-26 Thread Jochem Maas
[EMAIL PROTECTED] wrote:
Thanks, I already had prefork installed.  I solved the problem by 
heaven help those that walk the threaded path heh :-)
changing to php 5 from php 4.
IC interesting to know.
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] Define constants: awkward usage?

2005-01-26 Thread Jochem Maas
tony wrote:
Hi all,
I got this sets(20) of defined constants which using them as keys to an
array
eg
define(FNAME, fname);
farray = array( FNAME = hello ,...);
my question is how do I insert that directly into a javascript(to do
some client validation)
I need this:
var fname = document.addrform.fname.value
var fname = document.addrform.{FName}.value//don't work
var fname = document.addrform.{'FName'}.value//don't work
var fname = document.addrform.[FName].value//don't work
I know this work, but messey
$tmp = FNAME;
var fname = document.addrform.{$tmp}.value
you could try sprintf()/printf():
$output = sprintf('var fname = document.addrform.%s.value', FNAME );
or
printf('var fname = document.addrform.%s.value', FNAME );
I'am finding the use of define constants rather awkward. does anyone
make much use of them?
yes. :-) for...
session varnames
post/get varnames
bitwise flags
er...?
Thanks
Tony
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] Developer needed in London

2005-01-28 Thread Jochem Maas
Underodog H.R. wrote:
Sorry for using the list in this way, wont happen again.
wtf. 'they' posted it twice with the same message... thats the
definition of 'again'.
the fact that 'they' can't even spell their company name correctly
would make me think twice about working there ;-)
Underodog H.R. [EMAIL PROTECTED]
 ^ !!!
And why is a degree so important if 'all' they want if a monkey who
can do D/HTML, PHP  MySQL - these are the easiest IT wotsits on
the planet, ok playing minesweeper is easier :-). I mean easy as in
accessible not easy as in 'no hard work or study needed'
anyone can go to the local college and train to be an electrician
but you need a degree to write php code??
---
nuff of that, I've had too much coffee and too many traffic jams this morning.
PLEASE DON¹T REPLY TO THIS MESSAGE THROUGH THE LIST RESPOND DIRECT TO
[EMAIL PROTECTED]
Job Opportunity:
Web Developer/Designer In-house in London (not outsourced).
A great opportunity to join a young vibrant company working on exciting high
profile projects. Would suit recent graduates and experienced pro's alike. A
strong background in web technologies and programming is essential, good
working knowledge of; D/HTML, PHP, MySQL is necessary, other technologies
(Flash etc) are a bonus. Please apply by sending your CV to
[EMAIL PROTECTED]
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP-DB] Re: [PHP] Re: [PHP-DB] Developer needed in London

2005-01-28 Thread Jochem Maas
Jochem Maas wrote:
Underodog H.R. wrote:
Sorry for using the list in this way, wont happen again.

wtf. 'they' posted it twice with the same message... thats the
definition of 'again'.
I just noticed that they crossposted rather than post twice.
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] Re: [PHP] Re: [PHP-DB] Developer needed in London

2005-01-28 Thread Jochem Maas
Martin Norland wrote:
Jochem Maas wrote:
Jochem Maas wrote:
Underodog H.R. wrote:
Sorry for using the list in this way, wont happen again.

I just noticed that they crossposted rather than post twice.
That's three times now I've seen the statement that it won't happen again!
Unforgivable!
Seriously though - their name is set to Underodog - that *is* pretty 
damned bad.  Unless they're manually tweaking the From: field everytime 
they send mail from jobs@ - in which case, woops.

( I don't subscribe to general because I like getting *some* work done @ 
work - otherwise I'd just be 'at the ready' for support all day long - 
afaik it's fairly high traffic, yes?)
er. yes :-) actually i talking with a couple of guys off list about building
a 'parrot' which will auto answer newbie-emails :-)
Cheers,
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] if statement

2005-01-28 Thread Jochem Maas
Craig Hoffman wrote:
Hi There,
I am trying to write an if statement to see if an array has any values 
in it and if it does do something.

for example:
$ticklist2 = array('$values)
if (array_values(empty($ticklist2))){
empty() is used to check whether a var isset
and is not null,  or false - and it returns a boolean
value not an array;
php -r '
$a = null;
$b = false;
$c = ;
var_dump($a,$b,$c);
if (empty($a)) { echo \$a is empty.\n; }
if (empty($b)) { echo \$b is empty.\n; }
if (empty($c)) { echo \$c is empty.\n; }
'
array_values() expected an array as its argument.
maybe it can auto-cast any var it receives to an array
but I don't know (I never use it like that anyway.)
what is does do return an array with an associative keys
'replaced' with numeric keys - come to think of it I don't
use this function at all. any have a good use for the
function, just out of interest?
if you want to remove empty values:
php -r '
$a = array(yeah, null, , yeah, baby!);
var_dump($a,array_filter($a));
'
if you want to remove empty values and duplicates:
php -r '
$a = array(yeah, null, , yeah, baby!);
var_dump($a,array_unique(array_filter($a)));
'
do something
} else {
do something else
}

php -r '
$a = array( null, null );
var_dump($a);
if ($a) { echo \$a has items.\n; }
if ($aCnt = count($a)) { echo \$a has {$aCnt} items.\n; }
$b = array();
if ($b) { echo \$b has items.\n; }
if (empty($b)) { echo \$b is empty.\n; }
$c = array(f = me);
if (!$c) { echo \$c is empty items.\n; }
if (!empty($c)) { echo \$b is empty.\n; }
'
I just can't get this to work.  Any help would be great.
http://nl2.php.net/echo
http://nl2.php.net/empty
http://nl2.php.net/var_dump
http://nl2.php.net/array
http://nl2.php.net/array_unique
http://nl2.php.net/array_filter
Thanks, Craig H.
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] insert (database)

2005-02-02 Thread Jochem Maas
Yemi Obembe wrote:
the objective of the script below is to first search if a subscriber is already in a list before subscribing his email (so as to prevent double subscription). the select part works finebut the insert doesnt. know why?
 
if ($v = strtolower($_POST['email'])) {
what happens when $_POST['email'] is equal to
'script
document.location = http://www.evilkid.net/?stolencookie+document.cookie;
/script';
or something like that? Just something to think about.
$db = mysql_connect(mysql, usser, pw);
$con = mysql_select_db(ng,$db);
$sql = SELECT * FROM mytable WHERE email='$v';
$res = mysql_query( $sql ) ; 
if ($row = mysql_fetch_array($res)) {
  echo bYour email: u$v/u already in the listbr;
}
  else {
   $sql_in = INSERT INTO arcadia ('email') VALUES ('$v');
  $result_in = mysql_query($sql_in);
   echo bYour email: u$v/u subscribed!br;
you use different table names in each query. is that the intention?
}
  }
else {
include(index.php);
exit;
}

-
A passion till tomorrow,
Opeyemi Obembe | ng.clawz.com



-
Do you Yahoo!?
 Yahoo! Search presents - Jib Jab's 'Second Term'
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] insert (database)

2005-02-03 Thread Jochem Maas
Martin Norland wrote:
Jochem Maas wrote:
Yemi Obembe wrote:
the objective of the script below is to first search if a subscriber 
is already in a list before subscribing his email (so as to prevent 
double subscription). the select part works finebut the insert 
doesnt. know why?
 
if ($v = strtolower($_POST['email'])) {

what happens when $_POST['email'] is equal to
'script
document.location = 
http://www.evilkid.net/?stolencookie+document.cookie;
/script';

or something like that? Just something to think about.

Then the malicious user gets to send their own cookies for this site to 
another site of their choosing :P.  I would be more worried about it 
being equal to things like:

Spam my Enemy [EMAIL PROTECTED]
+ Spam my Enemy also [EMAIL PROTECTED]
+ etc.
  or
\r\nFrom: Idiots Inc. [EMAIL PROTECTED]
  or
'; Delete from arbitrary_table_name where 'yes'='yes
ah yes - that would an effective attack in/on an email ;-)
All of which are easily prevented with some attention to detail.  (or in 
some cases newer versions of software, which explicitly allow only one 
statement per call).  Finally - the concept of bind variables (or 
equivalent) are your friend (as Jochem already knows with firebird iirc).

yes indeed! praise to the guy who wrote the new firebird extension :-),
savin' my ass on a daily basis :-)
Cheers,
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] Form Mail Script/ Class

2005-02-03 Thread Jochem Maas
Malcolm JC Clark wrote:
I am looking for a good reliable php script/ class to process enquiries.
Maybe there is a de facto php script/ class like Matts perl Script Archive?
try phpmailer:
phpmailer.sourceforge.net
Kind Rgds
Malcolm
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] PHP5 classes mysql bug ?

2005-02-03 Thread Jochem Maas
Viacheslav Kaloshin wrote:
Here is testcase
PHP 5.0.3 (cli) (built: Dec 17 2004 10:47:41)
Copyright (c) 1997-2004 The PHP Group
Zend Engine v2.0.3, Copyright (c) 1998-2004 Zend Technologies
?php
class MySQL {
	private $mysql_link=0;
	private $mysql_result=0;
	
	function __construct()	{
		$host=localhost;
		$basename=test;
		$username=test;
		$userpassword=;
		
		$link=mysql_pconnect($host,$username,$userpassword);
		if($link)
			{ mysql_select_db($link); 
$this-$mysql_link=$link;
your syntax is wrong in the line above (and elsewhere), it should be:
$this-mysql_link=$link;
echo At constructor: ;
echo $this-$mysql_link;
echo \n;
return 0;
}
else
{
return 1;
}
}
function __destruct() {
echo At destructor ;
echo $this-$mysql_link;
echo \n;
if($this-$mysql_link) { 
mysql_close($this-$mysql_link); }
}

function query($query_string) {

echo before query: ;
echo $this-$mysql_link;
echo \n;
$this-$mysql_result=mysql_query($query_string);
// can change to this
#$this-$mysql_result=mysql_query($query_string, 
$this-$mysql_link);
echo after query: ;
echo $this-$mysql_link;
echo \n;
if($this-$mysql_result)
{ return 0; }
else
{ return 1; }
}
function result() {
return mysql_num_rows($this-$mysql_result);
}
function fetch() {
return mysql_fetch_array($this-$mysql_result, MYSQL_NUM);
}
function clear() {
return mysql_free_result($this-$mysql_result);
}

}
$m= new MySQL();
$m-query(select 1+2);
$res=$m-result(); 
$res=$m-fetch();
$m-clear();
$m-query(select 2+3);
$res=$m-result();
$res=$m-fetch();
$m-clear();

?
this script output should shwo the same id. but in my case i see next lines:
At constructor: Resource id #4
before query: Resource id #4
after query: Resource id #5
before query: Resource id #5
after query: Resource id #6
At destructor Resource id #6
What i am not understand?
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] JOIN problem

2005-02-08 Thread Jochem Maas
Zouari Fourat wrote:
am using mysql 3 so i can't do that subquery, how can we do that in mysql 3 ?
and neither can anyone else ;-)... rather a pain, but mysql.com have been 
kind enough
to give a detailed explaination on how to rewrite subselect queries as join 
queries:
If you put your brain in gear this page should tell what you need to know:  
http://dev.mysql.com/doc/mysql/en/rewriting-subqueries.html
If you get stuck, you know where the list is :-)

On Mon, 7 Feb 2005 19:47:08 +, Simon Rees
[EMAIL PROTECTED] wrote:
On Monday 07 February 2005 18:22, Zouari Fourat wrote:
Hello
I have 2 tables with two columns in each one (cloned tables) like this :
ID int(6)
UserName varchar(25)
and i would like to select usernames from table1 that doesnt appear in
table2 so i did this :
Depending on which database you're using you may be able to do this:
SELECT a.username
FROM table1 a
WHERE a.username NOT IN ( SELECT b.username FROM table2 b )
cheers Simon
--
~~
Simon Rees  |  [EMAIL PROTECTED]  |
ORA-03113: end-of-file on communication channel
~~

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


Re: [PHP-DB] Notice: Undefined index: op

2005-02-22 Thread Jochem Maas
Martin Norland wrote:
J. Connolly wrote:
...
You may want to use a different quoting style - I can't recall the name, 
but it's taken from perl
HEREDOC. (i believe its custom to write it in capitals,)
echo EOF
form action=$_SERVER[PHP_SELF] method=POST
...
the rest of your stuff, then on its own line right at the beginning of 
the line (no tabs/etc. :( )
...
EOF;

it basically echo's until it sees that delimiter, that could be EOD or 
STOP or whatever (well, there might be reserved words issues - I could 
more easily check if I could remember the name of the quoting style...)

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


Re: [PHP-DB] php5-sessions next

2005-03-03 Thread Jochem Maas
mel list_php wrote:
Dear Martin,
Thank you very much for that, I made the suggested changes.
The problem was again coming from the session.save_path directive which 
was not well configured.

With your settings I know have a wonderful display of undefined index, 
coming from all that non instantiated variables...at least I know what I 
have to do now!!
you have 3 options with these kinds of errors:
1. change error_reporting to not include NOTICEs
2. change all the relevant code so that all vars are initialized (possibly lots 
of work)
3. use the '@' sign on the vars to repress the errors e.g:
if (@$_GET['rule']) {
// take over world
}
I wouldn't recommend 3 unless its a specific case and you know what you're doing

One thing:
I use @session_start() because in the other case I have a warning a 
session has already been started. On the other had  have to call it at 
the beginning of each script.
Is there a way to test that?
you may be able to get away with testing to see whether session_id() returns
an empty string or not (i.e. if its empty you still have to start the session)
although I would recommend rewriting your session starting code so that you
only call session_start() in one place - if you put all this code in
a seperate file you can then require_once() the file as and when you need it.
With php5 I also saw than a script having a white line and only later on 
the ?php is not interpreted but displayed as text.
Any reason for that?
that doesn't sound like it should be happening - post some code please.
Once again thank you for your help, and sorry I should have displayed 
the errors at the beginning.
now you know :-) - the next time someone hits the list with a similar case 
you can
'parrot' Martin's tips!

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


Re: [PHP-DB] Expiry Date ($date function)

2005-03-03 Thread Jochem Maas
Ron Piggott wrote:
That strtotime is a neat little command.  With a bit more searching I found
that this works:
$expiry_date = strtotime(+21 days);
$expiry_date = date('Y-m-d', $expiry_date);
echo $expiry_date;
The computer couldn't cope with me doing it in just one line --- I got a
parse error.
the computer coped when I did it on oneline, maybe you had a typo or 
something:
echo date(Y-m-d, strtotime(+21 days));
sidenote: I use doublequotes here because its easier when testing in a linux
shellbut unless you need string interpolation its better to use single
quotes for your strings.
Ron
- Original Message -
From: Calvin Lough [EMAIL PROTECTED]
To: Ron Piggott [EMAIL PROTECTED]; PHP DB php-db@lists.php.net
Sent: Wednesday, March 02, 2005 10:50 AM
Subject: Re: [PHP-DB] Expiry Date ($date function)

The strtotime function should work the best.
$add_twentyone = strtotime(+21 days);
I dont know if that will work or not. I just found that method in the
php doc and it looked interesting. Hopefully it will work for you.
Calvin
On Wed, 2 Mar 2005 04:41:04 -0500, Ron Piggott
[EMAIL PROTECTED] wrote:
I figured out that the syntax below creates the date in the way it may
be
stored in a mySQL table:
$todays_date=DATE('Y-m-d');
Is there any way to add 21 days to this as an expiry date?  For example
if
the date was March 20th 2005 21 days would be in April --- is there any
way
of dealing with this?
Ron
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



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


  1   2   >