Re: [PHP-DB] pls clue in the clueless..:)

2003-01-08 Thread Rick Widmer
At 12:27 AM 1/8/03 -0800, Shantu Roy wrote:



Warning: MySQL Connection Failed: Can't connect to local MySQL server 
through socket '/tmp/mysql.sock' (2) in /usr/www/htdocs/test.php on line 2
Could not connect: Can't connect to local MySQL server through socket 
'/tmp/mysql.sock' (2)

It is not a passwd or server running issue and the mysql server is running 
local to the web server.  I can use a mysql client to connect to the 
server just fine.  Any ideas?

I bet you don't have a mysql.sock file in /tmp/.  There will be one on your 
system somewhere.  Run the MySQL client and execute the status 
command  \s  to find the proper location.  Then edit your php.ini 
file.  Find the setting for  mysql.default_socket  and set it to the proper 
location.  You must restart Apache for php.ini changes to take effect.

Rick


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



Re: [PHP-DB] join query/relational database question

2003-01-06 Thread Rick Widmer
At 04:09 PM 1/6/03 -0500, Doug Parker wrote:

I have a relational database issue that I'll simplify for the sake of this 
post.  I have one table, called clients,  that has an id and the company 
name.  For example:

id | company
---
46  Jones Inc.
54  Baker Inc.

etc.

I have another table called projects, that looks like this:

id | company_id | status
---
1   46  Active
2   54  Inactive


id | company_id | status|   company

1   46  Active  Jones Inc.
2   54  InactiveBaker 
Inc.

SELECT id, company.company_id, status, company
FROM projects
LEFT JOIN Companies USING( company_id )
ORDER BY company

Rick


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




Re: [PHP-DB] Newbie q: problem with mysql_connect() on hosted service

2002-12-27 Thread Rick Widmer
At 10:45 AM 12/27/02 +0100, Baumgartner Jeffrey wrote:


Fatal error: Call to undefined function: mysql_connect() in
/home/.sites/22/site13/web/werks/formtest2.php on line 8


This means that MySQL is not enabled within PHP.  There is nothing you can 
do about it.  The hosting company needs to enable access to MySQL, probably 
by re-compiling PHP and Apache.  The exact fix depends on operating system, 
web server, and how PHP is compiled.

Rick


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



Re: [PHP-DB] Help Needed

2002-12-26 Thread Rick Widmer
At 02:36 PM 12/26/02 +0700, dufronte wrote:


Hi.
I juz installed a RedHat 8.0 on my machine.
But then I have a problem in configuring Apache 2.0.4 to use PHP 4.20..


Apache 2 and PHP are not ready for prime time.  If you must use Apache 2 
with PHP, you are on the bleeding edge, and should plan on helping debug 
the combination.

Certainly there are some combinations of versions and configurations that 
do work, but there are many, many more that do not.  If you have time to 
study and test Apache 2 + PHP, I'm sure your help would be welcome.

If you want it to just work, you should be using Apache 1.3.


Rick


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



Re: [PHP-DB] How can I use PHP to duplicate a mysql template database?

2002-12-17 Thread Rick Widmer
At 07:59 PM 12/16/02 -0800, Daevid Vincent wrote:

I need to use PHP to duplicate the schema of a database. This seems like
it should be a simple task -- taking a 'template' db and cloning it with
a new name.



The easiest way I know of is at the command line:

mysqldump -p -u root  name_of_existing_database schemafile

mysql -p -u root
mysql create database newdatabase;
mysql grant whatever on newdatabase.* to whoever
mysql exit

mysql -p -u root newdatabase  schemafile

The commands typed into the mysql interpreter must be done by a user with 
rights to create databases, the final mysql command where you import the 
schemafile must be done with a user having rights to create tables within 
the new database, the mysqldump can be done by any user with select rights 
to all tables in the existing database.


And
$sql .= CREATE TABLE IP_Dept (;
$sql .=   IP_Addr int(10) unsigned NOT NULL default
'0',;
$sql .=   DeptID int(10) unsigned NOT NULL default
'0';
$sql .= );;


With MySQL, you only get one sql statement per call to mysql_query, so call 
it here, empty the $sql variable and start on the next table.  Also, a 
trailing semicolon is not allowed in the $sql variable, so end with  $sql 
.= ); instead of $sql .= );;


Don't complain, this is a feature that prevents a common database attack 
where someone adds ;drop table users; at the end of one of your queries by 
poisoning user input.


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



RE: [PHP-DB] foreach loop from MySQL select query to HTML select list

2002-11-28 Thread Rick Widmer
At 10:40 AM 11/29/02 +1100, Gavin Amm wrote:

hmm, interesting to know the mysql_fetch_array() by default returns an array
that's associative AND numeric - very useful to know  something i'll have
to look into more, thanks Jason.


Using PHP's built in template system...

$result_dept = mysql_query( SELECT DepartmentID, Department
 FROM Departments
 ORDER BY Department );
...

select name=dept
  option-select-/option
  ? while( extract( mysql_fetch_array($result_dept, MYSQL_ASSOC))) : ?
  option value=?=$DepartmentID??=$Department?/option
  ? endwhile ?
/select

i do have one more problem though, i need to run the loop a 2nd time later

in the page in exactly the same way, but nothing is returned.
i just copied  pasted the code from one section of the page to the next.
do i need to reset one of the vaiables?



mysql_data_seek()

http://www.php.net/manual/en/function.mysql-data-seek.php

Rick


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




Re: [PHP-DB] Enum table entry

2002-10-19 Thread Rick Widmer
At 11:48 PM 10/18/02 -0500, Shiloh Madsen wrote:



 For instance, a series of checkboxes with items such as abjuration, 
conjuration, divination, and others, which will all have a numeric value 
which gets plugged into the enum field. for instance, if a user selected 
abjuration, and divination, it would be plugged into sql as 1, 3

Assuming your field is:

school enum( 'abjuration', 'conjuration', 'divination', ... ),

The database will return, 'abjuration,divination' in the example listed
above, and it will expect the same kind of string when setting the field
in an UPDATE or INSERT query.



(or however enum data is input into its column). That being the case how 
do i utilize php to get this to work? what kind of form elements etc... 
The problem im seeing with checkboxes are that they are discreet and dont 
group together, so i cant get all the data to go into one column in mysql. 
Hopefully i havent horribly confused the issue and some kind soul out 
there can tell me how to send this data across. As a double nice 
thing...how would you write it to pull the data back out...ie, convert 1, 
3 to show abjuration, divination? Thanks for the help in advance.



To get the data in/out of the database you can do something like this:


Start with an array of possible choices, because you are going to
have to act on each possible choice.

$SchoolChoices = array( 'Abjuration', 'Conjuration', 'Divination', ... );




To setup the variables from the table for display.  Note the value
from the database is in the string $School.


reset( $SchoolChoices );

while( list( , $Choice ) = each( $SchoolChoices )) {
   $VarName = 'School' . $Choice;
   $$VarName = ereg( $Choice, $School ) ? 'CHECKED' : '';
   }



Now you can send the form displayed below with the values from
the database.



FORM Method=GET  ...

INPUT Type=checkbox Name=SchoolAbjuration Value=?=$SchoolAbjuration?
INPUT Type=checkbox Name=SchoolConjuration Value=?=$SchoolConjuration?
INPUT Type=checkbox Name=SchoolDivination Value=?=$SchoolDivination?
...
/FORM

===


After the user enters the form, you can decode the fields and put the
data into a string for storage in the database with:


reset( $SchoolChoices );

$School = '';
while( list( , $Choice ) = each( $SchoolChoices )) {
   if( 'on' == $_get( School$Choice ))  {
  $School .= ',' . $Choice;
  }
   }

$School = substr( $School, 1 );


Now you can INSERT/UPDATE the database with $School to set the enum field.




You can create the checkbox fields from $SchoolChoices with the following:

reset( $SchoolChoices );

while( list( , $Choice ) = each( $SchoolChoices )) {
   $VarName = 'School' . $Choice;
   echo INPUT Type=\checkbox\ Name=\$VarName\ Value=\$$VarName\;
   }




For extra credit, figure out how you can create the $SchoolChoices array
from the output of the following query:

   DESCRIBE TableName School;

(Yes you can send this to mysql_query, and get the possible values of the 
enum.)



Rick  


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



Re: [PHP-DB] Server Upgrade and DB Move(s)

2002-10-15 Thread Rick Widmer

At 03:14 PM 10/15/02 -0400, [EMAIL PROTECTED] wrote:

I am in the process of upgrading my UNIX hardware and moving web sites from
two different servers on to one server.  I am curious as to opinions about
moving/replicating the databases and peoples experiences.  For the two that
i have already done, i have taken a rather manual approach which was easy,
but the rest are more dynamically generated and dependent on MySQL and I
was looking for a tool that could replicate the structure and data onto a
new server.

Anybody find an easy way to do this.  I could write something in PHP, but
if i could, it's probably already written


So how different are the servers?  Moving databases between similar servers 
can be as simple as
copying the database directories, and executing a CREATE DATABASE dbname 
command for each.
You will also need to GRANT access to various users as needed.  That is 
part of the mysql database
and the easiest way to merge them is by issuing the needed commands.

Rick


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




RE: [PHP-DB] enum and bad planning

2002-10-01 Thread Rick Widmer

At 03:35 PM 10/1/02 -0400, John W. Holmes wrote:
You should BENCHMARK the two solutions and see which is faster. Or use
EXPLAIN to see if there is any difference.

I have no doubt this will be slower.  Oh well, he wanted to keep the table 
definitions.

Don't forget to consider the time required for the programmer to change all 
the programs
that already have been coded.

Rick


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




Re: [PHP-DB] Date Concat?

2002-09-20 Thread Rick Widmer

At 07:07 AM 9/20/02 -0500, Rankin, Randy wrote:
 SELECT
 DATE_FORMAT(start_date, '%M %d, %Y') as start_date,
 DATE_FORMAT(end_date, '%M %d, %Y') as end_date
 FROM training

This produces the following:

 start_date: September 16, 2002
 end_date: Sepetember 20, 2001

Based on the above, I would like to echo out something like this:

 You will be in training September 16 - 20, 2002.

SELECT CONCAT( DATE_FORMAT(start_date, '%M  %d' ), ' - ',
  DATE_FORMAT( end_date, '%d, %Y' )) AS dates, ...

Rick


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




Re: [PHP-DB] Split Fields into 2 Tables or All in One?

2002-07-26 Thread Rick Widmer

At 02:18 PM 7/26/02 -0400, Monty wrote:
Anyone have any tips or links to tips about update multiple tables based on
data received from a form?

If you use varchar fields the cost of empty fields is very small.  The 
decision on
using a separate table should be based in things like how many addresses you
allow someone to enter.  If you allow zero or one address per entry go ahead
and put it in one table.  If you want to allow zero or more phone numbers that
would call for a separate table with the number and type of phone.

Rick


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




Re: [PHP-DB] PHP database

2002-07-15 Thread Rick Widmer


Hello

I'm to have database, but server's administrator refuses to install MySQL
nor PHP MySQL support :( He told me he won't install it and I should use
textfiles if I want to have database.


Sounds like time too find another hosting provider.


Rick


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