Re: [PHP-DB] date format question
Hi, You could try to change date(m) to date(n), and date(d) to date(j). It looks that sometimes mktime() doesn't remove the trailing zeroes and returns totally different dates. The other thing you could try is $date = date(F dS, Y g:i:s A, date(U)+18000); this one takes the number seconds of seconds between the Unix Epoch (January 1 1970) and the currend time and adds 5 hours (18000 seconds) Hope this helps Dobromir Velev -Original Message- From: Matt Nigh [EMAIL PROTECTED] To: php-db [EMAIL PROTECTED] Date: Wednesday, November 28, 2001 03:49 Subject: [PHP-DB] date format question hi, i'm wondering if anyone could help me in formatting a date so it is 5 hours ahead of the server time. here's the code i'm using but it doesn't seem to work: $date = date(F dS, Y g:i:s A, mktime(date(g)+5,date(i),date(s),date(m),date(d),date(Y)) ); i've already looked in the manual and around the net for stuff, but wasn't able to find anything for what i needed. if anyone could help out, i'd appreciate it. thanks, Matt -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DB] ?? If Table Exists, Drop Table, then Create Table ??
Hi, All MySQL version higher than 3.22 support the following syntaxis DROP TABLE IF EXISTS tbl_name HTH Dobromir Velev -Original Message- From: MrBaseball34 [EMAIL PROTECTED] To: [EMAIL PROTECTED] [EMAIL PROTECTED] Date: Tuesday, November 27, 2001 18:37 Subject: [PHP-DB] ?? If Table Exists, Drop Table, then Create Table ?? Table Creation Script from SQL Server... if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Orders]') and OBJECTPROPERTY(id, N'IsUserTable') = 1) drop table [dbo].[Orders] GO CREATE TABLE [dbo].[Orders] ( [OrderID] [int] IDENTITY (1, 1) NOT NULL, . . . . ); GO Is there anything like the first line from mySQL? I need to check if a table exists and drop it if it does so it can be recreated. I do not have access to any admin facilities on my host so I need to be able to do this in a script I can modify. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DB] Storing JPEG's in MySQL -- Is it possible?
Try header('Content-type: image/gif'); Regards, Andrey Hristov IcyGEN Corporation http://www.icygen.com BALANCED SOLUTIONS - Original Message - From: PaulC [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Wednesday, November 28, 2001 10:28 AM Subject: Re: [PHP-DB] Storing JPEG's in MySQL -- Is it possible? I am using this to read the uploaded file $attach_data = addslashes(fread(fopen($HTTP_POST_FILES['attachment']['tmp_name'], r), filesize($HTTP_POST_FILES['attachment']['tmp_name']))); I'm then insterting that into the MySQL database, along with the $attachment_type It works fine for a GIF, but a JPEG isn't displayed correctly. Thanks, Paul Ck Raju [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... Please show your script, so that we can answer you better. CK Raju On Tuesday 27 November 2001 16:37, PaulC wrote: Hi, I've wrote a bit of code to upload a file, and store it in a MySQL longblob field. If I upload a GIF, and store it in MySQL I am able to retrieve it fine using a PHP script. However, a JPEG uploads, but cannot be retrieved successfully. (I get a broken image symbol in IE) Does anybody know why this is??? Thanks, Paul -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DB] Storing JPEG's in MySQL -- Is it possible?
excuses, image/jpeg - Original Message - From: PaulC [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Wednesday, November 28, 2001 10:28 AM Subject: Re: [PHP-DB] Storing JPEG's in MySQL -- Is it possible? I am using this to read the uploaded file $attach_data = addslashes(fread(fopen($HTTP_POST_FILES['attachment']['tmp_name'], r), filesize($HTTP_POST_FILES['attachment']['tmp_name']))); I'm then insterting that into the MySQL database, along with the $attachment_type It works fine for a GIF, but a JPEG isn't displayed correctly. Thanks, Paul Ck Raju [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... Please show your script, so that we can answer you better. CK Raju On Tuesday 27 November 2001 16:37, PaulC wrote: Hi, I've wrote a bit of code to upload a file, and store it in a MySQL longblob field. If I upload a GIF, and store it in MySQL I am able to retrieve it fine using a PHP script. However, a JPEG uploads, but cannot be retrieved successfully. (I get a broken image symbol in IE) Does anybody know why this is??? Thanks, Paul -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] JOIN - Not working.
I have read the parts of the manual(s) but am just not grasping something... I have 2 tables, one holds the Property ID etc., and the other holds all the Property Details. They are connected by a field called 'PropertyID' which is a unique ID that appears in both records. I want to count the number of records in PropertyDetails that have an entry in a field called 'Image1Desc', but I need to do this based on a previously chosen field from Property called 'PropertyType'. However, the code below is simply not giving the results I need: $phselect = select COUNT(*) AS phTotal from properties LEFT JOIN propertydetails ON properties.PropertyID=propertydetails.PropertyID where ((propertydetails.Image1Desc='') AND (properties.PropertyType='$PropertyType')); $phresult = mysql_query ($phselect,$conID); while ($phrow = mysql_fetch_array($phresult)) { $phTotal = $phrow[phTotal]; PRINT td align=\right\$phresult/td\n; } // end WHILE Is there an obvious problem here and can anyone help? Martin E. Koss M: 07946-706459 E: [EMAIL PROTECTED] -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] set NULL vaules in Access DB
Hello, I have some problems to put Null value in a field of a data base in Access. This field is numeric type. When I submit the form, variable has $var='', I set it $var=Null, but ODBC returns an error: Warning: SQL error: [Microsoft][Controlador ODBC Microsoft Access] No coinciden los tipos de datos en la expresión de criterios., SQL state 22005 in SQLExecDirect in c:\win\apache\htdocs\do_access_db.php4 on line 214 Can anybody help me? Thanks Silvia Mahiques -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DB] query to check valid emails
select * from tbl where email like %$email%; This will find the string stored in the variable '$email' in the column 'email' Adjust having the '%' at the end, the beginning or both (as above) as they will find the string '$email' at end or at the beginning of the string stored in the column 'email' respectively. Russ On Sat, 24 Nov 2001 13:06:50 -0500 Noah Spitzer-Williams [EMAIL PROTECTED] wrote: what's the LIKE query to see if an email address is valid? For example, in PHP it's something like if (eregi(^[0-9a-z]([-_.]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*\\.[a-z]{2,3}$,$ email,$check)) { echo valid; } i want to sort through rows in a db and look for invalid email addresses so like, select * from tbl where email like ??? Thanks! - Noah -- TradeMyTraffic! Banner Exchange http://www.trademytraffic.com -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] #---# Believe nothing - consider everything Russ Michell Anglia Polytechnic University Webteam Room 1C 'The Eastings' East Road, Cambridge e: [EMAIL PROTECTED] w: www.apu.ac.uk/webteam www.theruss.com #---# -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DB] query to check valid emails
No this will not do what the original poster requested it will be something like the following select * from table where email regexp ^[0-9a-z]([-_.]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*\\.[a-z]{2,3}$; Regards Jon -- Jon Farmer Systems Programmer, Entanet www.enta.net Tel 01952 428969 Mob 07763 620378 PGP Key available, send email with subject: Send PGP Key select * from tbl where email like %$email%; This will find the string stored in the variable '$email' in the column 'email' Adjust having the '%' at the end, the beginning or both (as above) as they will find the string '$email' at end or at the beginning of the string stored in the column 'email' respectively. Russ On Sat, 24 Nov 2001 13:06:50 -0500 Noah Spitzer-Williams [EMAIL PROTECTED] wrote: what's the LIKE query to see if an email address is valid? For example, in PHP it's something like if (eregi(^[0-9a-z]([-_.]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*\\.[a-z]{2,3}$,$ email,$check)) { echo valid; } i want to sort through rows in a db and look for invalid email addresses so like, select * from tbl where email like ??? Thanks! - Noah -- TradeMyTraffic! Banner Exchange http://www.trademytraffic.com -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] #---# Believe nothing - consider everything Russ Michell Anglia Polytechnic University Webteam Room 1C 'The Eastings' East Road, Cambridge e: [EMAIL PROTECTED] w: www.apu.ac.uk/webteam www.theruss.com #---# -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DB] query to check valid emails
Glad someone knows more than I do, or that chap would be right up a certain creek without a paddle.. Cheers Russ On Wed, 28 Nov 2001 09:44:26 - Jon Farmer [EMAIL PROTECTED] wrote: No this will not do what the original poster requested it will be something like the following select * from table where email regexp ^[0-9a-z]([-_.]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*\\.[a-z]{2,3}$; Regards Jon -- Jon Farmer Systems Programmer, Entanet www.enta.net Tel 01952 428969 Mob 07763 620378 PGP Key available, send email with subject: Send PGP Key select * from tbl where email like %$email%; This will find the string stored in the variable '$email' in the column 'email' Adjust having the '%' at the end, the beginning or both (as above) as they will find the string '$email' at end or at the beginning of the string stored in the column 'email' respectively. Russ On Sat, 24 Nov 2001 13:06:50 -0500 Noah Spitzer-Williams [EMAIL PROTECTED] wrote: what's the LIKE query to see if an email address is valid? For example, in PHP it's something like if (eregi(^[0-9a-z]([-_.]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*\\.[a-z]{2,3}$,$ email,$check)) { echo valid; } i want to sort through rows in a db and look for invalid email addresses so like, select * from tbl where email like ??? Thanks! - Noah -- TradeMyTraffic! Banner Exchange http://www.trademytraffic.com -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] #---# Believe nothing - consider everything Russ Michell Anglia Polytechnic University Webteam Room 1C 'The Eastings' East Road, Cambridge e: [EMAIL PROTECTED] w: www.apu.ac.uk/webteam www.theruss.com #---# -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] #---# Believe nothing - consider everything Russ Michell Anglia Polytechnic University Webteam Room 1C 'The Eastings' East Road, Cambridge e: [EMAIL PROTECTED] w: www.apu.ac.uk/webteam www.theruss.com #---# -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DB] JOIN Very SLOW...
I would suggest changing COUNT(*) to COUNT(properties.PropertyID) Regards Jon -- Jon Farmer Systems Programmer, Entanet www.enta.net Tel 01952 428969 Mob 07763 620378 PGP Key available, send email with subject: Send PGP Key - Original Message - From: Martin E. Koss [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Wednesday, November 28, 2001 10:09 AM Subject: [PHP-DB] JOIN Very SLOW... The following does work but it extremely slow. $phselect = select COUNT(*) AS phTotal from properties LEFT JOIN propertydetails ON properties.PropertyID=propertydetails.PropertyID where ((propertydetails.Image1Desc='') AND (properties.PropertyType='$PropertyType')); $phresult = mysql_query ($phselect,$conID); while ($phrow = mysql_fetch_array($phresult)) { $phTotal = $phrow[phTotal]; PRINT td align=\right\$phTotal/td\n; } // end WHILE Is there an obvious problem here and can anyone help? Martin E. Koss M: 07946-706459 E: [EMAIL PROTECTED] -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DB] JOIN Very SLOW...
You use LEFT JOIN so your query is optimized. Probably your tables are big, you don't have many MB of RAM. When you have big RAM, I think that tables reside in memory and join of 5 tables every 600,000 rows is done for 4-5s. May be you have to increase some of the buffers sizes of mysql. Regards, Andrey Hristov - Original Message - From: Martin E. Koss [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Wednesday, November 28, 2001 12:09 PM Subject: [PHP-DB] JOIN Very SLOW... The following does work but it extremely slow. $phselect = select COUNT(*) AS phTotal from properties LEFT JOIN propertydetails ON properties.PropertyID=propertydetails.PropertyID where ((propertydetails.Image1Desc='') AND (properties.PropertyType='$PropertyType')); $phresult = mysql_query ($phselect,$conID); while ($phrow = mysql_fetch_array($phresult)) { $phTotal = $phrow[phTotal]; PRINT td align=\right\$phTotal/td\n; } // end WHILE Is there an obvious problem here and can anyone help? Martin E. Koss M: 07946-706459 E: [EMAIL PROTECTED] -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] Using variables within a SELECT statement
I'm working on an application that selects a user's userid if their password and login match. If the login and password match I want my variable $cir to run its own select statement and return its corresponding contactid...for this example we'll say that value = 5. I then want to plug in $cir into my select statement that will show the user the list of his/her contacts and only theirs. This seems to be the select statement that's giving my problems. $query = select * from my_contacts where contactid=$cir; Whenever I run my script I get an error saying that I have a problem with my sql syntax. I know that the problem is with the variable becuase it runs fine with a value in it. I've tried writing the $cir as '$cir' and '\$cir' but nothing seems to work. Can anyone help. Thanks in advance Kevin -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DB] Using variables within a SELECT statement
Try, $query=select * from my_contacts where contactid like '$cir'; Kevin Ruiz wrote: I'm working on an application that selects a user's userid if their password and login match. If the login and password match I want my variable $cir to run its own select statement and return its corresponding contactid...for this example we'll say that value = 5. I then want to plug in $cir into my select statement that will show the user the list of his/her contacts and only theirs. This seems to be the select statement that's giving my problems. $query = select * from my_contacts where contactid=$cir; Whenever I run my script I get an error saying that I have a problem with my sql syntax. I know that the problem is with the variable becuase it runs fine with a value in it. I've tried writing the $cir as '$cir' and '\$cir' but nothing seems to work. Can anyone help. Thanks in advance Kevin -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- Sliante, Richard S. Crawford mailto:[EMAIL PROTECTED] http://www.mossroot.com AIM: Buffalo2K ICQ: 11646404 Yahoo!: rscrawford MSN: [EMAIL PROTECTED] When you have lost the ability to laugh at yourself, you have lost the ability to think straight. --Clarence Darrow Push the button, Max! -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP-DB] inserting mysql data using php array???
Very interesting. I didn't know you could use SET with an INSERT. I tried this on MySQL and it worked. Dunno if it's standard SQL, but it didn't work on MSAccess and MS SQLServer (the only other DBs I have at hand to test it with). I wonder what other DBs it works on, because you could be painting yourself into a corner if you had to move to another platform. TIM -What if the Hokey-Pokey really is what it's all about? -Original Message- From: Jonathan Hilgeman [mailto:[EMAIL PROTECTED]] I actually have an easy way to do INSERTs like this. First I create the array: $MyArray[field] = value; $MyArray[name] = Jonathan; $MyArray[age] = 123; $MyArray[email] = $email_address; and then I define this function somewhere in a function library: function Array2Query($dbArray) { foreach($dbArray as $dbField = $dbValue) { $dbQuery .= $dbField='$dbValue',; } $dbQuery = substr($dbQuery,0,strlen($dbQuery)-1); return $dbQuery; } and then I just create the query: $Query = INSERT INTO table SET . Array2Query($MyArray); $Result = mysql_query($Query); Hope it helps. - Jonathan -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] query + loop problem
Hi there everyone: I have a generic query containing variables, substituted for values dependant upon specific circumstances: //query the DB on the basis of searches employing text input fields (LIKE) if($sql_clause == 'LIKE') { $sql = SELECT * FROM $table WHERE $field $sql_clause '%$query%'; } //query the DB on the basis of searches employing select menus ('=') else if($sql_clause == '=') { $sql = SELECT * FROM $table WHERE $field $sql_clause '$query'; } $result = mysql_query($sql,$connect) or printerror(Query Failure!,06); $numrows = mysql_num_rows($result); Instead of the usual 'hard-coded' method within the loop as below: //loop using hard-coded variables while($row = mysql_fetch_array($result)) { $field1 = $row[fieldname1]; $field2 = $row[fieldname2]; //etc }//end while loop I'd like to be able to have this dynamically enabled as below: //loop using relevant field names to display correct page content while($row = mysql_fetch_array($result)) { //generic method of extracting rownames according to '$table' (above) goes here }//end loop Does anyone have a clue how to do this??? Many Thanks! Russ #---# -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DB] query + loop problem
echo table\r\n; while($row = mysql_fetch_assoc($result)) { // if assoc is not available - will work but double results foreach($row as $key = $value){ echo trtd$key/tdtd$value/td/tr\r\n; } }//end loop echo /table\r\n; HTH Regards, Andrey Hristov IcyGEN Corporation http://www.icygen.com BALANCED SOLUTIONS - Original Message - From: Russ Michell [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Wednesday, November 28, 2001 5:36 PM Subject: [PHP-DB] query + loop problem Hi there everyone: I have a generic query containing variables, substituted for values dependant upon specific circumstances: file://query the DB on the basis of searches employing text input fields (LIKE) if($sql_clause == 'LIKE') { $sql = SELECT * FROM $table WHERE $field $sql_clause '%$query%'; } file://query the DB on the basis of searches employing select menus ('=') else if($sql_clause == '=') { $sql = SELECT * FROM $table WHERE $field $sql_clause '$query'; } $result = mysql_query($sql,$connect) or printerror(Query Failure!,06); $numrows = mysql_num_rows($result); Instead of the usual 'hard-coded' method within the loop as below: file://loop using hard-coded variables while($row = mysql_fetch_array($result)) { $field1 = $row[fieldname1]; $field2 = $row[fieldname2]; file://etc }//end while loop I'd like to be able to have this dynamically enabled as below: file://loop using relevant field names to display correct page content while($row = mysql_fetch_array($result)) { file://generic method of extracting rownames according to '$table' (above) goes here }//end loop Does anyone have a clue how to do this??? Many Thanks! Russ #---# -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DB] inserting mysql data using php array???
Actually, there is another way of doing it. The prerequisite for this method, is that you have an auto_incremented column. If you have that, then all you have to do is insert a value into one of the columns, then grab mysql_insert_id, and update all columns, corresponding to that auto_incremented value. That's what I ended up doing. - Original Message - From: Tim Foster [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Wednesday, November 28, 2001 10:37 Subject: RE: [PHP-DB] inserting mysql data using php array??? Very interesting. I didn't know you could use SET with an INSERT. I tried this on MySQL and it worked. Dunno if it's standard SQL, but it didn't work on MSAccess and MS SQLServer (the only other DBs I have at hand to test it with). I wonder what other DBs it works on, because you could be painting yourself into a corner if you had to move to another platform. TIM -What if the Hokey-Pokey really is what it's all about? -Original Message- From: Jonathan Hilgeman [mailto:[EMAIL PROTECTED]] I actually have an easy way to do INSERTs like this. First I create the array: $MyArray[field] = value; $MyArray[name] = Jonathan; $MyArray[age] = 123; $MyArray[email] = $email_address; and then I define this function somewhere in a function library: function Array2Query($dbArray) { foreach($dbArray as $dbField = $dbValue) { $dbQuery .= $dbField='$dbValue',; } $dbQuery = substr($dbQuery,0,strlen($dbQuery)-1); return $dbQuery; } and then I just create the query: $Query = INSERT INTO table SET . Array2Query($MyArray); $Result = mysql_query($Query); Hope it helps. - Jonathan -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DB] query + loop problem
Try using mysql_query to describe the table in question (describe $table), and use the output as a list of field names (and types). I wrote a generic script to do this for an app... can provide if needed (although it sure looks a little hacked right now, hmmm) -db Russ Michell wrote: Hi there everyone: I have a generic query containing variables, substituted for values dependant upon specific circumstances: //query the DB on the basis of searches employing text input fields (LIKE) if($sql_clause == 'LIKE') { $sql = SELECT * FROM $table WHERE $field $sql_clause '%$query%'; } //query the DB on the basis of searches employing select menus ('=') else if($sql_clause == '=') { $sql = SELECT * FROM $table WHERE $field $sql_clause '$query'; } $result = mysql_query($sql,$connect) or printerror(Query Failure!,06); $numrows = mysql_num_rows($result); Instead of the usual 'hard-coded' method within the loop as below: //loop using hard-coded variables while($row = mysql_fetch_array($result)) { $field1 = $row[fieldname1]; $field2 = $row[fieldname2]; //etc }//end while loop I'd like to be able to have this dynamically enabled as below: //loop using relevant field names to display correct page content while($row = mysql_fetch_array($result)) { //generic method of extracting rownames according to '$table' (above) goes here }//end loop Does anyone have a clue how to do this??? Many Thanks! Russ #---# -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- -- Dan Barton Terrestrial Program Biologist Asst. Data Manager Point Reyes Bird Observatory http://www.prbo.org [EMAIL PROTECTED] [EMAIL PROTECTED] -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[Fwd: [PHP-DB] JOIN - Not working.]
-- -- Dan Barton Terrestrial Program Biologist Asst. Data Manager Point Reyes Bird Observatory http://www.prbo.org [EMAIL PROTECTED] [EMAIL PROTECTED] ---BeginMessage--- Try: select sum(if(whatever=whatever,1,0)) as whatever from wherever where whatever=whatever; This is a pretty fast command for simple cross-tabs (outperforms left join?) and is easier to understand for a quick fix. You can also write a loop that creates a query with multiple rows like: select sum(if(whatever=whatever,1,0)) as whatever1 select sum(if(whatever=whatever,1,0)) as whatever2 select sum(if(whatever=whatever,1,0)) as whatever3 select sum(if(whatever=whatever,1,0)) as whatever4 from wherever where whatever=whatever group by whatever; yay! -db Martin E. Koss wrote: I have read the parts of the manual(s) but am just not grasping something... I have 2 tables, one holds the Property ID etc., and the other holds all the Property Details. They are connected by a field called 'PropertyID' which is a unique ID that appears in both records. I want to count the number of records in PropertyDetails that have an entry in a field called 'Image1Desc', but I need to do this based on a previously chosen field from Property called 'PropertyType'. However, the code below is simply not giving the results I need: $phselect = select COUNT(*) AS phTotal from properties LEFT JOIN propertydetails ON properties.PropertyID=propertydetails.PropertyID where ((propertydetails.Image1Desc='') AND (properties.PropertyType='$PropertyType')); $phresult = mysql_query ($phselect,$conID); while ($phrow = mysql_fetch_array($phresult)) { $phTotal = $phrow[phTotal]; PRINT td align=\right\$phresult/td\n; } // end WHILE Is there an obvious problem here and can anyone help? Martin E. Koss M: 07946-706459 E: [EMAIL PROTECTED] -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- -- Dan Barton Terrestrial Program Biologist Asst. Data Manager Point Reyes Bird Observatory http://www.prbo.org [EMAIL PROTECTED] [EMAIL PROTECTED] ---End Message--- -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DB] query + loop problem
Nice one folks! Thanks for your help - it's amazing what happens to one's brain once you start to think about the problem in hand enough (enough that is, to attmept to make it make sense to others!..) - I sussed the problem, using a similar method described to me my several of you. (and a little bit of RFTM on my part r.e: mysql_fetch_assoc() and mysql_fetch_array() ... Many thanks for your help. Russ On Wed, 28 Nov 2001 17:49:54 +0200 Andrey Hristov [EMAIL PROTECTED] wrote: echo table\r\n; while($row = mysql_fetch_assoc($result)) { // if assoc is not available - will work but double results foreach($row as $key = $value){ echo trtd$key/tdtd$value/td/tr\r\n; } }//end loop echo /table\r\n; HTH Regards, Andrey Hristov IcyGEN Corporation http://www.icygen.com BALANCED SOLUTIONS - Original Message - From: Russ Michell [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Wednesday, November 28, 2001 5:36 PM Subject: [PHP-DB] query + loop problem Hi there everyone: I have a generic query containing variables, substituted for values dependant upon specific circumstances: file://query the DB on the basis of searches employing text input fields (LIKE) if($sql_clause == 'LIKE') { $sql = SELECT * FROM $table WHERE $field $sql_clause '%$query%'; } file://query the DB on the basis of searches employing select menus ('=') else if($sql_clause == '=') { $sql = SELECT * FROM $table WHERE $field $sql_clause '$query'; } $result = mysql_query($sql,$connect) or printerror(Query Failure!,06); $numrows = mysql_num_rows($result); Instead of the usual 'hard-coded' method within the loop as below: file://loop using hard-coded variables while($row = mysql_fetch_array($result)) { $field1 = $row[fieldname1]; $field2 = $row[fieldname2]; file://etc }//end while loop I'd like to be able to have this dynamically enabled as below: file://loop using relevant field names to display correct page content while($row = mysql_fetch_array($result)) { file://generic method of extracting rownames according to '$table' (above) goes here }//end loop Does anyone have a clue how to do this??? Many Thanks! Russ #---# -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] #---# Believe nothing - consider everything Russ Michell Anglia Polytechnic University Webteam Room 1C 'The Eastings' East Road, Cambridge e: [EMAIL PROTECTED] w: www.apu.ac.uk/webteam www.theruss.com #---# -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] db connect problems.
Hello, wonder if anyone can debug this script. I copied it from an example in a book. There is a .php file and a .inc file This is the .inc file: ?php //common_db.inc $dbhost = 'localhost'; $dbusername = 'root'; $dbuserpassword = ''; $default_dbname = 'mysql'; $MYSQL_ERRNO = ''; $MYSQL_ERROR = ''; function db_connect($dbname=) { global $dbhost, $dbusername, $dbuserpassword, $default_dbname, $dbname; global $MYSQL_ERRNO, $MYSQL_ERROR; $link_id = mysql_connect($dbhost, $dbusername, $dbuserpassword); if(!$link_id) { $MYSQL_ERRNO = 0; $MYSQL_ERROR = Connection failed to the host $dbhost.; return 0; } else if(empty($dbname) !mysql_select_db($default_dbname)) { $MYSQL_ERRNO = mysql_errno(); $MYSQL_ERROR = mysql_error(); return 0; } else return $link_id; } function sql_error() { global $MYSQL_ERRNO, $MYSQL_ERROR; if(empty($MYSQL_ERROR)) { $MYSQL_ERRNO = mysql_errno(); $MYSQL_ERROR = mysql_error(); } return $MYSQL_ERRNO: $MYSQL_ERROR; } ? the .php file is like this: ?php //show_more_db.php include ./common_db.inc; $link_id = db_connect('sample_db'); $result = mysql_query(SELECT * FROM user, $link_id); while($query_data = mysql_fetch_row($result)) { ? ?php echo ',$query_data[1],' is also php ' known as ,$query_data[3],P; } ? Sorry about poxy formatting, hope it is legible. I seem to have a problem passing the database to the db_connect() function within the .php script. The $default_dbname variable within the .inc file is always selected instead of the argument I pass. Anyone help me please? Ta. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re[2]: [PHP-DB] Problem with Oracle connection
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Hello B., This happens with either 4.0.4 or 4.0.6. What did you do to solve it? JBB Tuesday, November 27, 2001, 2:37:17 PM, you wrote: BP le ven 23-11-2001 à 02:18, Jonathan B. Bayer a écrit : -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Hello php-db, We have a RedHat 7.1 server with a stock install. I recompiled PHP from the source RPM in order to add oracle support. It mostly works, but we are having a problem where it apparently randomly loses the connection to the database. It is an oracle database which is on the local network; another system (a Sun) doesn't have this problem, so that rules out the database. Does anybody have any experience with this happening? Thanks in advance. JBB BP I guess you are using php-4.0.6, I met this problem on a Debian with BP this PHP version. BP B. - -- Best regards, Jonathanmailto:[EMAIL PROTECTED] -BEGIN PGP SIGNATURE- Version: GnuPG v1.0.6 (MingW32) Comment: For info see http://www.gnupg.org iEYEARECAAYFAjwFGWIACgkQxQhxe/20cF7wjQCeJIaavah7gSIvISAoxYOzdYls zjgAoKQlNiYMy3D/xfybpKL7LBrqOhVf =3Bo6 -END PGP SIGNATURE- -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] resource id #2, #3, #4......
I've come across yet another problem. I have a table set up that houses four things, a person's real name, username, pass, and id. The id is used to join another table which houses that persons contacts. I've been validating the user and pass by comparing the number of rows that the sql statement returns. Once the user submits their user/pass they're sent to the validation page where the user and pass are compared and if they're valid another sql statement takes place: $ci = select contactid from users where username='$username' and password='$password'; $cir = mysql_query($ci)or die(Couldn't execute); echo(htmlheadMETA HTTP-EQUIV=\refresh\ CONTENT=\0;url=db.php\/head/html); I've registered the variables $username, $password, $cir and if the user is validated they're sent to the contacts page. On the contacts page I'm trying to select which contacts to show based on the contact id. This is what the code looks like on the page where the contacts are going to be displayed... mysql_connect(localhost) or die(couldn't connect); mysql_select_db(act) or die(couldn't connect to the database); $ci = select contactid from users where username='$username' and password='$password'; $cir = mysql_query($ci) or die(Couldn't execute); $query = select * from my_contacts where contactid='$cir'; $result = mysql_query($query) or die( mysql_error() ); When I try to print $cir to see if anything's getting passed I keep getting something that reads resource id #2. If I were rename the variables in the $ci, $cir, and $query lines, run the code, and try to print $cir again I'd get resource id #3 and so on. Does anyone know what this means and how I can work around it. Thanks for your time. Kevin -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DB] resource id #2, #3, #4......
On Thursday 29 November 2001 01:29, Kevin Ruiz wrote: I've come across yet another problem. [snip] $ci = select contactid from users where username='$username' and password='$password'; $cir = mysql_query($ci) or die(Couldn't execute); $query = select * from my_contacts where contactid='$cir'; $result = mysql_query($query) or die( mysql_error() ); When I try to print $cir to see if anything's getting passed I keep getting something that reads resource id #2. [snip] Does anyone know what this means and how I can work around it. $cir does NOT contain the actual results of your query. It is only a *pointer* to your results. To get at the actual result(s): print table\n; while ($line = mysql_fetch_array($cir)) { print \ttr\n; while(list($col_name, $col_value) = each($line)) { print \t\ttd$col_value/td\n; } print \t/tr\n; } print /table\n; Read the manual for full details. hth -- Jason Wong - Gremlins Associates - www.gremlins.com.hk /* Total strangers need love, too; and I'm stranger than most. */ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] Re: Using variables within a SELECT statement
$query=select * from my_contacts where contactid like \$cir\; Fred Kevin Ruiz [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... I'm working on an application that selects a user's userid if their password and login match. If the login and password match I want my variable $cir to run its own select statement and return its corresponding contactid...for this example we'll say that value = 5. I then want to plug in $cir into my select statement that will show the user the list of his/her contacts and only theirs. This seems to be the select statement that's giving my problems. $query = select * from my_contacts where contactid=$cir; Whenever I run my script I get an error saying that I have a problem with my sql syntax. I know that the problem is with the variable becuase it runs fine with a value in it. I've tried writing the $cir as '$cir' and '\$cir' but nothing seems to work. Can anyone help. Thanks in advance Kevin -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DB] JOIN - Not working.
Sorry, that was a bit hasty. I was just trying to get the method across quickly. SELECT SUM(IF(Image1Desc!='insert default value of Image1Desc here'),1,0) as phTotal from PropertyDetails; would count the number of entries where Image1Desc!=default in PropertyDetails. This can be used in combination with a LEFT JOIN or a WHERE or a GROUP BY or anything else to perform the operation you're interested in, like: SELECT SUM(IF(Image1Desc!='insert default value of Image1Desc here'),1,0) as phTotal from PropertyDetails WHERE 'fieldname'='condition'; or SELECT SUM(IF(Image1Desc!='insert default value of Image1Desc here'),1,0) as phTotal from PropertyDetails WHERE 'fieldname'='condition'; or SELECT SUM(IF(PropertyDetails.Image1Desc!='insert default value of Image1Desc here'),1,0) as phTotal from Properties LEFT JOIN PropertyDetails ON Properties.PropertyID=propertydetails.PropertyID WHERE Properties.PropertyType='$PropertyType'; Add a GROUP BY if you need one. Cheers, db Martin E. Koss wrote: Ehm...? You've lost me. Perhaps a real-world example may have explained it better. All the repeated 'whatever' kind of makes it a bit unexplained. Martin. -Original Message- From: Daniel Barton [mailto:[EMAIL PROTECTED]] Sent: 28 November 2001 4:14 PM To: Martin E. Koss Subject: Re: [PHP-DB] JOIN - Not working. Try: select sum(if(whatever=whatever,1,0)) as whatever from wherever where whatever=whatever; This is a pretty fast command for simple cross-tabs (outperforms left join?) and is easier to understand for a quick fix. You can also write a loop that creates a query with multiple rows like: select sum(if(whatever=whatever,1,0)) as whatever1 select sum(if(whatever=whatever,1,0)) as whatever2 select sum(if(whatever=whatever,1,0)) as whatever3 select sum(if(whatever=whatever,1,0)) as whatever4 from wherever where whatever=whatever group by whatever; yay! -db Martin E. Koss wrote: I have read the parts of the manual(s) but am just not grasping something... I have 2 tables, one holds the Property ID etc., and the other holds all the Property Details. They are connected by a field called 'PropertyID' which is a unique ID that appears in both records. I want to count the number of records in PropertyDetails that have an entry in a field called 'Image1Desc', but I need to do this based on a previously chosen field from Property called 'PropertyType'. However, the code below is simply not giving the results I need: $phselect = select COUNT(*) AS phTotal from properties LEFT JOIN propertydetails ON properties.PropertyID=propertydetails.PropertyID where ((propertydetails.Image1Desc='') AND (properties.PropertyType='$PropertyType')); $phresult = mysql_query ($phselect,$conID); while ($phrow = mysql_fetch_array($phresult)) { $phTotal = $phrow[phTotal]; PRINT td align=\right\$phresult/td\n; } // end WHILE Is there an obvious problem here and can anyone help? Martin E. Koss M: 07946-706459 E: [EMAIL PROTECTED] -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- -- Dan Barton Terrestrial Program Biologist Asst. Data Manager Point Reyes Bird Observatory http://www.prbo.org [EMAIL PROTECTED] [EMAIL PROTECTED] -- -- Dan Barton Terrestrial Program Biologist Asst. Data Manager Point Reyes Bird Observatory http://www.prbo.org [EMAIL PROTECTED] [EMAIL PROTECTED] -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP-DB] inserting mysql data using php array???
Interesting. A bit tiedious, I suppose. Seems like it'd be a bit more overhead than I'd care to have, but an interesting technique nonetheless. TIM -I date this girl for two years and then the nagging starts: I wanna know your name. - Mike Binder -Original Message- From: Ubaidul Khan [mailto:[EMAIL PROTECTED]] Sent: Wednesday, November 28, 2001 10:04 AM To: Tim Foster Cc: [EMAIL PROTECTED] Subject: Re: [PHP-DB] inserting mysql data using php array??? Actually, there is another way of doing it. The prerequisite for this method, is that you have an auto_incremented column. If you have that, then all you have to do is insert a value into one of the columns, then grab mysql_insert_id, and update all columns, corresponding to that auto_incremented value. That's what I ended up doing. - Original Message - From: Tim Foster [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Wednesday, November 28, 2001 10:37 Subject: RE: [PHP-DB] inserting mysql data using php array??? Very interesting. I didn't know you could use SET with an INSERT. I tried this on MySQL and it worked. Dunno if it's standard SQL, but it didn't work on MSAccess and MS SQLServer (the only other DBs I have at hand to test it with). I wonder what other DBs it works on, because you could be painting yourself into a corner if you had to move to another platform. TIM -What if the Hokey-Pokey really is what it's all about? -Original Message- From: Jonathan Hilgeman [mailto:[EMAIL PROTECTED]] I actually have an easy way to do INSERTs like this. First I create the array: $MyArray[field] = value; $MyArray[name] = Jonathan; $MyArray[age] = 123; $MyArray[email] = $email_address; and then I define this function somewhere in a function library: function Array2Query($dbArray) { foreach($dbArray as $dbField = $dbValue) { $dbQuery .= $dbField='$dbValue',; } $dbQuery = substr($dbQuery,0,strlen($dbQuery)-1); return $dbQuery; } and then I just create the query: $Query = INSERT INTO table SET . Array2Query($MyArray); $Result = mysql_query($Query); Hope it helps. - Jonathan -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DB] db connect problems.
well, I didn't debug this massive script, but maybe you just want to connect to a mysql database? then this is the short way: $user = your_username_for_the_database; $pass = your_password_for_the_database; $con = mysql_connect(your_host, $user, $pass); if(!$con) { print no connection; } I really don't know if this is what you're asking for Leo Kuiper Building a map in order to find what's not lost but left behind. - Beth Orton - Original Message - From: Ian [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Wednesday, November 28, 2001 5:52 PM Subject: [PHP-DB] db connect problems. Hello, wonder if anyone can debug this script. I copied it from an example in a book. There is a .php file and a .inc file This is the .inc file: ?php //common_db.inc $dbhost = 'localhost'; $dbusername = 'root'; $dbuserpassword = ''; $default_dbname = 'mysql'; $MYSQL_ERRNO = ''; $MYSQL_ERROR = ''; function db_connect($dbname=) { global $dbhost, $dbusername, $dbuserpassword, $default_dbname, $dbname; global $MYSQL_ERRNO, $MYSQL_ERROR; $link_id = mysql_connect($dbhost, $dbusername, $dbuserpassword); if(!$link_id) { $MYSQL_ERRNO = 0; $MYSQL_ERROR = Connection failed to the host $dbhost.; return 0; } else if(empty($dbname) !mysql_select_db($default_dbname)) { $MYSQL_ERRNO = mysql_errno(); $MYSQL_ERROR = mysql_error(); return 0; } else return $link_id; } function sql_error() { global $MYSQL_ERRNO, $MYSQL_ERROR; if(empty($MYSQL_ERROR)) { $MYSQL_ERRNO = mysql_errno(); $MYSQL_ERROR = mysql_error(); } return $MYSQL_ERRNO: $MYSQL_ERROR; } ? the .php file is like this: ?php //show_more_db.php include ./common_db.inc; $link_id = db_connect('sample_db'); $result = mysql_query(SELECT * FROM user, $link_id); while($query_data = mysql_fetch_row($result)) { ? ?php echo ',$query_data[1],' is also php ' known as ,$query_data[3],P; } ? Sorry about poxy formatting, hope it is legible. I seem to have a problem passing the database to the db_connect() function within the .php script. The $default_dbname variable within the .inc file is always selected instead of the argument I pass. Anyone help me please? Ta. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] DB/pgsql.php
Hello I would like to create some PHP scripts which do not rely on a specific DB. As first DB I use PostgreSQL so I have included the line: include_once(DB/pgsql.php); in my script but I get the following error: Fatal error: Class db_common: Cannot inherit from undefined class pear in /usr/local/lib/php/DB/common.php on line 28 What am I doing wrong ? Regards, Marc -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DB] db connect problems.
which is even better, all I tried to do was to point out just how simple it can be... btw. I prefer mysql_fetch_array ps. (ik woon in koudekerk, kilometertje of 8 van waddinxveen en werk als tekenaar op een ingenieursburo... klein wereldje) Leo Kuiper Building a map in order to find what's not lost but left behind. - Beth Orton - Original Message - From: Roel Mulder [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Wednesday, November 28, 2001 11:15 PM Subject: Re: [PHP-DB] db connect problems. Or what about: common_db.inc with just the following: (which you would for security reasons put in a directory outside the webroot, and rename the file to .common_db.inc (with a . in front of it)) ?php $dbhost = 'localhost'; $dbusername = 'root'; $dbuserpassword = ''; $default_dbname = 'mysql'; ? show_more_db.php with ?php include ./common_db.inc; mysql_connect($dbhost, $dbusername, $dbuserpassword) or die (bCouldn't connect to specified server/b); mysql_select_db($default_dbname) or die (bError, no database found sweetheart/b); $sql = SELECT * FROM user; $result = mysql_query($sql); while ($row = mysql_fetch_row($result)) { echo ($row[1].br\n); } mysql_close(); ? Groetend, Roel Mulder At 22:52 28-11-2001 +0100, you wrote: well, I didn't debug this massive script, but maybe you just want to connect to a mysql database? then this is the short way: $user = your_username_for_the_database; $pass = your_password_for_the_database; $con = mysql_connect(your_host, $user, $pass); if(!$con) { print no connection; } I really don't know if this is what you're asking for Leo Kuiper Building a map in order to find what's not lost but left behind. - Beth Orton - Original Message - From: Ian [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Wednesday, November 28, 2001 5:52 PM Subject: [PHP-DB] db connect problems. Hello, wonder if anyone can debug this script. I copied it from an example in a book. There is a .php file and a .inc file This is the .inc file: ?php //common_db.inc $dbhost = 'localhost'; $dbusername = 'root'; $dbuserpassword = ''; $default_dbname = 'mysql'; $MYSQL_ERRNO = ''; $MYSQL_ERROR = ''; function db_connect($dbname=) { global $dbhost, $dbusername, $dbuserpassword, $default_dbname, $dbname; global $MYSQL_ERRNO, $MYSQL_ERROR; $link_id = mysql_connect($dbhost, $dbusername, $dbuserpassword); if(!$link_id) { $MYSQL_ERRNO = 0; $MYSQL_ERROR = Connection failed to the host $dbhost.; return 0; } else if(empty($dbname) !mysql_select_db($default_dbname)) { $MYSQL_ERRNO = mysql_errno(); $MYSQL_ERROR = mysql_error(); return 0; } else return $link_id; } function sql_error() { global $MYSQL_ERRNO, $MYSQL_ERROR; if(empty($MYSQL_ERROR)) { $MYSQL_ERRNO = mysql_errno(); $MYSQL_ERROR = mysql_error(); } return $MYSQL_ERRNO: $MYSQL_ERROR; } ? the .php file is like this: ?php //show_more_db.php include ./common_db.inc; $link_id = db_connect('sample_db'); $result = mysql_query(SELECT * FROM user, $link_id); while($query_data = mysql_fetch_row($result)) { ? ?php echo ',$query_data[1],' is also php ' known as ,$query_data[3],P; } ? Sorry about poxy formatting, hope it is legible. I seem to have a problem passing the database to the db_connect() function within the .php script. The $default_dbname variable within the .inc file is always selected instead of the argument I pass. Anyone help me please? Ta. Mulder Technisch Advies Postbus 69 NL-2740 AB WADDINXVEEN tel. 0182-640184 fax. 0182-640185 http://www.mta.nl -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] GROUP BY with a string column
Can the SUM keyword in SELECT be generalized to strings? A tipical use for the SUM keyword is: SELECT column1, SUM(column2) FROM table GROUP BY column1 This works only if column2 contains numbers (and SUM is the mathematical sum). What about obtain the same behaviour, when column2 contains strings (and SUM is string concatenation)? Anyone help me please? Thank you Mauro Boscarol http://www.boscarol.com -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] Re: Oracle row limit support
Hello, Tomas V.V.Cox wrote: Manuel Lemos wrote: But it does not work with computed columns like those that apply functions (COUNT, SUM, SUBSTRING, etc...). The code assumes that you are actually selecting only real table fields. I think it also does not work with columns with table name prefixes. That's partially true. But it's a common practise to use column aliases in conyunction with functions (and a must for assoc fetchs) and this is supported by the code I wrote, for ex: select count(field) as count from foo; That would work, but you require people to change their queries. I guess that does not work as general practice because. Also if Oracle name a sum(foo) column as sum will be trivial to add it. I ran a query without the column alias and seems that Oracle names that column with the entire name for ex: sum(foo). If that is true the support could be completed. I don't think it will ever work. When you do not use column alias, you will be asking Oracle to to apply a function to a column that does not exist in the inner query. If you think it works, just show me the result query that you end up executing. Regards, Manuel Lemos -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DB] GROUP BY with a string column
On Mié 28 Nov 2001 19:42, you wrote: Can the SUM keyword in SELECT be generalized to strings? A tipical use for the SUM keyword is: SELECT column1, SUM(column2) FROM table GROUP BY column1 This works only if column2 contains numbers (and SUM is the mathematical sum). What about obtain the same behaviour, when column2 contains strings (and SUM is string concatenation)? With which database engine? -- Porqué usar una base de datos relacional cualquiera, si podés usar PostgreSQL? - Martín Marqués |[EMAIL PROTECTED] Programador, Administrador, DBA | Centro de Telematica Universidad Nacional del Litoral - -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] php and mysql security problem
Dear all I had a security problem with my homepage. I'm using the IIS 4 to host my webpage, and i got the php to run as the script of the webpage and the database i'm using for the database is mysql. Here is my question : There is a table in mysql which will let user to input some records to, then the user will update and retreive the records. But what i to do is limit the user update to the record which the user should be. I mean when user1 had insert a record into table, and he found out that there is some update need to do for the record he just inset, so he update that record. but i don't want other people can update his record. Is there also possible for php to grab the username and password from the window base which logged on to a Domain and pass it to MYSQL!! Thx Jack [EMAIL PROTECTED] -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]