Re: [PHP] Questions from a Newbie

2010-10-17 Thread Alexis
Ethan,you have the end of line semi colons enclosed in double 
quotes..move them to the true end of line.


On 17/10/10 04:45, Christian Heinrich wrote:

Am Sonntag, den 17.10.2010, 01:00 -0400 schrieb Ethan Rosenberg:

Dear List -

Here are some questions, which I am sure are trivial, but I am a
newbie, and cannot find the answers online

I cannot get the following to work.  In my Firefox [Iceweasel]
browser, I enter the following URL: [w/ the http]

   localhost/CreateNew.php All I get is a blank browser screen.

The code  contained in the file CreateNew.php is:

/*
   *  Create Database test22
   */
   htmlbody
?php
$cxn = mysqli_connect($host,$user,$password);
echoCreate database test22;
echoCreate table Names2
(
  RecordNum Int(11) Primary Key Not null default=1 auto_increment,
  FirstName varchar(10),
  LastName varchar(10),
  Height  decimal(4,1),
  Weight0 decimal(4,1),
  BMI decimal(3,1)
  Date0 date
);

echo   Create table Visit2
(
  Indx Int(7) Primary Key Not null auto_increment,
  Weight decimal(4,1) not null,
  StudyDate date not null,
  RecordNum Int(11)
);

  $sql= SHOW DATABASES;
?
/body/html

If I search for test22 or Visit2, nothing is found.

I would also like to be able to add data to a table, using PHP, which
I can do in MySQL as:
load data infile '/home/ethan/Databases/tester21.dat.' replace into
table Names fields escaped by '\\' terminated by '\t'  lines
terminated by '\n' ;

Thanks in advance.

Ethan
===
Using Debian(sid)






Hi,

maybe you also want to take a look at PDO - http://php.net/pdo

Regards
Christian




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



Re: [PHP] Questions from a Newbie

2010-10-17 Thread Christian Heinrich
Am Sonntag, den 17.10.2010, 01:00 -0400 schrieb Ethan Rosenberg:
 Dear List -
 
 Here are some questions, which I am sure are trivial, but I am a 
 newbie, and cannot find the answers online
 
 I cannot get the following to work.  In my Firefox [Iceweasel] 
 browser, I enter the following URL: [w/ the http]
 
   localhost/CreateNew.php All I get is a blank browser screen.
 
 The code  contained in the file CreateNew.php is:
 
 /*
   *  Create Database test22
   */
   htmlbody
 ?php
 $cxn = mysqli_connect($host,$user,$password);
 echoCreate database test22;
 echoCreate table Names2
 (
  RecordNum Int(11) Primary Key Not null default=1 auto_increment,
  FirstName varchar(10),
  LastName varchar(10),
  Height  decimal(4,1),
  Weight0 decimal(4,1),
  BMI decimal(3,1)
  Date0 date
 );
 
 echo   Create table Visit2
 (
  Indx Int(7) Primary Key Not null auto_increment,
  Weight decimal(4,1) not null,
  StudyDate date not null,
  RecordNum Int(11)
 );
 
  $sql= SHOW DATABASES;
 ?
 /body/html
 
 If I search for test22 or Visit2, nothing is found.
 
 I would also like to be able to add data to a table, using PHP, which 
 I can do in MySQL as:
 load data infile '/home/ethan/Databases/tester21.dat.' replace into 
 table Names fields escaped by '\\' terminated by '\t'  lines 
 terminated by '\n' ;
 
 Thanks in advance.
 
 Ethan
 ===
 Using Debian(sid)  
 
 
 


Hi,

maybe you also want to take a look at PDO - http://php.net/pdo

Regards
Christian


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



RE: [PHP] Questions from a Newbie

2010-10-17 Thread Tommy Pham
 -Original Message-
 From: Alexis [mailto:phplis...@antonakis.co.uk]
 Sent: Sunday, October 17, 2010 4:10 AM
 To: php-general@lists.php.net
 Subject: Re: [PHP] Questions from a Newbie
 
 Ethan,you have the end of line semi colons enclosed in double
 quotes..move them to the true end of line.
 

Even if he does move the semicolons to outside the quote, it doesn't do what he 
intended as maintaining the database.  His code merely echo the SQL syntax for 
viewing and not actually executing the SQL syntax, which is what I think he 
intended.  In which case, he's better off using phpMyAdmin.

Regards,
Tommy

 On 17/10/10 04:45, Christian Heinrich wrote:
  Am Sonntag, den 17.10.2010, 01:00 -0400 schrieb Ethan Rosenberg:
  Dear List -
 
  Here are some questions, which I am sure are trivial, but I am a
  newbie, and cannot find the answers online
 
  I cannot get the following to work.  In my Firefox [Iceweasel]
  browser, I enter the following URL: [w/ the http]
 
 localhost/CreateNew.php All I get is a blank browser screen.
 
  The code  contained in the file CreateNew.php is:
 
  /*
 *  Create Database test22
 */
 htmlbody
  ?php
  $cxn = mysqli_connect($host,$user,$password);
  echoCreate database test22;
  echoCreate table Names2
  (
RecordNum Int(11) Primary Key Not null default=1
 auto_increment,
FirstName varchar(10),
LastName varchar(10),
Height  decimal(4,1),
Weight0 decimal(4,1),
BMI decimal(3,1)
Date0 date
  );
 
  echo   Create table Visit2
  (
Indx Int(7) Primary Key Not null auto_increment,
Weight decimal(4,1) not null,
StudyDate date not null,
RecordNum Int(11)
  );
 
$sql= SHOW DATABASES;
  ?
  /body/html
 
  If I search for test22 or Visit2, nothing is found.
 
  I would also like to be able to add data to a table, using PHP, which
  I can do in MySQL as:
  load data infile '/home/ethan/Databases/tester21.dat.' replace into
  table Names fields escaped by '\\' terminated by '\t'  lines
  terminated by '\n' ;
 
  Thanks in advance.
 
  Ethan
  ===
  Using Debian(sid)
 
 
 
 
 
  Hi,
 
  maybe you also want to take a look at PDO - http://php.net/pdo
 
  Regards
  Christian
 
 
 
 --
 PHP General Mailing List (http://www.php.net/) To unsubscribe, visit:
 http://www.php.net/unsub.php



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



[PHP]About Character Set

2010-10-17 Thread 肖晗
There is a download directory(to provide download links) in my site.
http://vedaclub.org/download/
Some of the filenames contain Chinese characters, which, however cannot be
recognized.
Is there anything I can do to solve problem?

Thanks in advance!


Re: [PHP] Re: strtotime

2010-10-17 Thread Tamara Temple


On Oct 17, 2010, at 12:58 AM, John Taylor-Johnston wrote:


According to this, I'm 44 not 45 :)p

$birthday = '1965-08-30';

//calculate years of age (input string: -MM-DD)

function birthday ($birthday){
  list($year,$month,$day) = explode(-,$birthday);
  $year_diff  = date(Y) - $year;
  $month_diff = date(m) - $month;
  $day_diff   = date(d) - $day;
  if ($day_diff  0 || $month_diff  0)


This will trigger anytime the current day of the month is less than 30.


$year_diff--;
  return $year_diff;
}

echo birthday ($birthday);




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



RE: [PHP] Re: strtotime

2010-10-17 Thread Tommy Pham
 -Original Message-
 From: John Taylor-Johnston [mailto:John.Taylor-
 johns...@cegepsherbrooke.qc.ca]
 Sent: Saturday, October 16, 2010 10:58 PM
 To: PHP-General
 Subject: [PHP] Re: strtotime
 
 According to this, I'm 44 not 45 :)p
 
 $birthday = '1965-08-30';
 
 //calculate years of age (input string: -MM-DD)
 
function birthday ($birthday){
  list($year,$month,$day) = explode(-,$birthday);
  $year_diff  = date(Y) - $year;
  $month_diff = date(m) - $month;
  $day_diff   = date(d) - $day;
  if ($day_diff  0 || $month_diff  0)

I think the problem is with the logic above.

$year_diff = 44
$month_diff = 2
$day_diff = -13

Since the $month_diff is positive meaning you're already passed your
birthdate.  If the $month_diff is 0 - your birth month, then you need to
check if the if it's past your birth day yet (negative $day_diff).

That logic should be changed to if if (($month_diff == 0  $day_diff  0)
|| $month_diff  0)

Then you're 45 ;)

Regards,
Tommy

$year_diff--;
  return $year_diff;
}
 
 echo birthday ($birthday);
 
 
 
 John Taylor-Johnston wrote:
  I'm working my way right now through the manual:
  http://ca.php.net/manual/en/function.strtotime.php.
 
 


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



Re: [PHP]About Character Set

2010-10-17 Thread Ashley Sheridan
On Sun, 2010-10-17 at 21:56 +0800, 肖晗 wrote:

 There is a download directory(to provide download links) in my site.
 http://vedaclub.org/download/
 Some of the filenames contain Chinese characters, which, however cannot be
 recognized.
 Is there anything I can do to solve problem?
 
 Thanks in advance!



The short answer is yes, remove the Chinese characters, however, I
think you were looking for something a little more automatic?

If the URL itself is causing the problem, maybe you could use the
urlencode() and urldecode() functions to make the filename for the URL
web-safe.

Another alternative that I've used before is to give each file an entry
in a DB and use a moniker to identify the file. The DB can handle all
sorts of extra functions in the future, such as allowing only specific
users to access a file, storing multiple versions of the same file
bearing the same name (on the server each version has a unique name, the
user need only know that they're requesting template.doc, version 3,
etc) and many other things.

Thanks,
Ash
http://www.ashleysheridan.co.uk




RE: [PHP] Questions from a Newbie

2010-10-17 Thread Ethan Rosenberg



At 01:41 AM 10/17/2010, Tommy Pham wrote:

 -Original Message-
 From: Ethan Rosenberg [mailto:eth...@earthlink.net]
 Sent: Saturday, October 16, 2010 10:01 PM
 To: php-general@lists.php.net
 Subject: [PHP] Questions from a Newbie

 Dear List -

 Here are some questions, which I am sure are trivial, but I am a newbie,
and
 cannot find the answers online

 I cannot get the following to work.  In my Firefox [Iceweasel] browser, I
 enter the following URL: [w/ the http]

   localhost/CreateNew.php All I get is a blank browser screen.

 The code  contained in the file CreateNew.php is:

 /*
   *  Create Database test22
   */
   htmlbody
 ?php
 $cxn = mysqli_connect($host,$user,$password);
 echoCreate database test22;
 echoCreate table Names2
 (
  RecordNum Int(11) Primary Key Not null default=1
auto_increment,
  FirstName varchar(10),
  LastName varchar(10),
  Height  decimal(4,1),
  Weight0 decimal(4,1),
  BMI decimal(3,1)
  Date0 date
 );

 echo   Create table Visit2
 (
  Indx Int(7) Primary Key Not null auto_increment,
  Weight decimal(4,1) not null,
  StudyDate date not null,
  RecordNum Int(11)
 );

  $sql= SHOW DATABASES;
 ?
 /body/html

 If I search for test22 or Visit2, nothing is found.

 I would also like to be able to add data to a table, using PHP, which I
can do
 in MySQL as:
 load data infile '/home/ethan/Databases/tester21.dat.' replace into table
 Names fields escaped by '\\' terminated by '\t'  lines terminated by '\n'
;

 Thanks in advance.

 Ethan
 ===
 Using Debian(sid)


You're reinventing the wheel that's been rolling along very smoothly for a
long time... Google 'phpmyadmin'.  Also, read this entire section [1].

Regards,
Tommy

[1] http://www.php.net/manual/en/book.mysqli.php


Tommy -

Thanks.

As I stated, I am a newbie.

1] I am trying to shorten the learning curve by asking some 
questions, which I understand are probably trivial.  A whole MySQLi 
list of functions at this point is to much for me.  I have to break 
the problem into manageable parts.


2] It has been my experience that using a GUI does not teach the 
whole subject.  Linux, which is the OS I use cannot be run from a GUI.


In the code being discussed, I wish to create a database and add two 
tables.  I also note a MySQL statement that can be used to add data 
to an existing table, and wish to be able to execute this statement 
using PHP.


So, therefore..

Let us try to answer the following two(2) questions:

a] What changes [other than moving the simicolons] have to be made to 
correct the code.


b] What books can you suggest to help w/ MySQL and PHP?  I already 
have the SQL, MySQL  PHP, and HTML books in the . for Dummies 
series.  I need something with a little more depth and detail.


Thanks to all for your excellent help.

Ethan

 Using Debian(sid)
 




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



Re: [PHP] Re: strtotime

2010-10-17 Thread John Taylor-Johnston

Yaay, I'm 45 now :).

Here is another nifty piece of code I found. How does this work? What is 
31556926?


function calculateAge($birthday){
return floor((time() - strtotime($birthday))/31556926);
}

echo calculateAge('1965-10-17');

http://ca.php.net/manual/en/function.floor.php

--
$birthday = '1965-08-30';

//calculate years of age (input string: -MM-DD)

  function birthday ($birthday){
list($year,$month,$day) = explode(-,$birthday);
$year_diff  = date(Y) - $year;
$month_diff = date(m) - $month;
$day_diff   = date(d) - $day;
#  if ($day_diff  0 || $month_diff  0)
if (($month_diff == 0  $day_diff  0) || $month_diff  0)
  $year_diff--;
return $year_diff;
  }

echo birthday ($birthday);


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



Re: [PHP] Re: strtotime

2010-10-17 Thread richard gray

 On 17/10/2010 21:34, John Taylor-Johnston wrote:

Yaay, I'm 45 now :).

Here is another nifty piece of code I found. How does this work? What 
is 31556926?




number of seconds in a year...?

Rich

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



Re: [PHP] Questions from a Newbie

2010-10-17 Thread a...@ashleysheridan.co.uk
Linux can be run as a GUI, using a window manager.

Aside from that, have a look at the manual pages on php.net, which give some 
good examples of how to use the various mysql functions.

Also, on your development machine, its a good idea to turn on errors, as it can 
indicate where these problems are. You can do this from the php.ini, look for 
display_errors.

Thanks,
Ash
http://www.ashleysheridan.co.uk

- Reply message -
From: Ethan Rosenberg eth...@earthlink.net
Date: Sun, Oct 17, 2010 19:22
Subject: [PHP] Questions from a Newbie
To: Tommy Pham tommy...@gmail.com, php-general@lists.php.net



At 01:41 AM 10/17/2010, Tommy Pham wrote:
  -Original Message-
  From: Ethan Rosenberg [mailto:eth...@earthlink.net]
  Sent: Saturday, October 16, 2010 10:01 PM
  To: php-general@lists.php.net
  Subject: [PHP] Questions from a Newbie
 
  Dear List -
 
  Here are some questions, which I am sure are trivial, but I am a newbie,
and
  cannot find the answers online
 
  I cannot get the following to work.  In my Firefox [Iceweasel] browser, I
  enter the following URL: [w/ the http]
 
localhost/CreateNew.php All I get is a blank browser screen.
 
  The code  contained in the file CreateNew.php is:
 
  /*
*  Create Database test22
*/
htmlbody
  ?php
  $cxn = mysqli_connect($host,$user,$password);
  echoCreate database test22;
  echoCreate table Names2
  (
   RecordNum Int(11) Primary Key Not null default=1
auto_increment,
   FirstName varchar(10),
   LastName varchar(10),
   Height  decimal(4,1),
   Weight0 decimal(4,1),
   BMI decimal(3,1)
   Date0 date
  );
 
  echo   Create table Visit2
  (
   Indx Int(7) Primary Key Not null auto_increment,
   Weight decimal(4,1) not null,
   StudyDate date not null,
   RecordNum Int(11)
  );
 
   $sql= SHOW DATABASES;
  ?
  /body/html
 
  If I search for test22 or Visit2, nothing is found.
 
  I would also like to be able to add data to a table, using PHP, which I
can do
  in MySQL as:
  load data infile '/home/ethan/Databases/tester21.dat.' replace into table
  Names fields escaped by '\\' terminated by '\t'  lines terminated by '\n'
;
 
  Thanks in advance.
 
  Ethan
  ===
  Using Debian(sid)
 

You're reinventing the wheel that's been rolling along very smoothly for a
long time... Google 'phpmyadmin'.  Also, read this entire section [1].

Regards,
Tommy

[1] http://www.php.net/manual/en/book.mysqli.php

Tommy -

Thanks.

As I stated, I am a newbie.

1] I am trying to shorten the learning curve by asking some 
questions, which I understand are probably trivial.  A whole MySQLi 
list of functions at this point is to much for me.  I have to break 
the problem into manageable parts.

2] It has been my experience that using a GUI does not teach the 
whole subject.  Linux, which is the OS I use cannot be run from a GUI.

In the code being discussed, I wish to create a database and add two 
tables.  I also note a MySQL statement that can be used to add data 
to an existing table, and wish to be able to execute this statement 
using PHP.

So, therefore..

Let us try to answer the following two(2) questions:

a] What changes [other than moving the simicolons] have to be made to 
correct the code.

b] What books can you suggest to help w/ MySQL and PHP?  I already 
have the SQL, MySQL  PHP, and HTML books in the . for Dummies 
series.  I need something with a little more depth and detail.

Thanks to all for your excellent help.

Ethan

  Using Debian(sid)
 



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



Re: [PHP] Re: strtotime

2010-10-17 Thread Tamara Temple


On Oct 17, 2010, at 2:34 PM, John Taylor-Johnston wrote:

Here is another nifty piece of code I found. How does this work?  
What is 31556926?


Number of second in a year? (31556926 / (24 * 60 * 60) yields  
365.2421...)



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



Re: [PHP] Questions from a Newbie

2010-10-17 Thread Tamara Temple


On Oct 17, 2010, at 1:22 PM, Ethan Rosenberg wrote:

At 01:41 AM 10/17/2010, Tommy Pham wrote:
 I cannot get the following to work.  In my Firefox [Iceweasel]  
browser, I

 enter the following URL: [w/ the http]


Whenever you get a blank screen running a php application, the place  
to look is the http server's error_log. This is frequently found in / 
var/log/httpd/error_log or /var/log/apache2/error_log. (If your system  
is hosted someplace else, it could very easily be in a different  
place). Typically you need root permission to read this file. Tail the  
file after you run your PHP script to see the most recent errors.



 The code  contained in the file CreateNew.php is:

 /*
   *  Create Database test22
   */
   htmlbody
 ?php
 $cxn = mysqli_connect($host,$user,$password);


Better to use the OO approach:

$cxn = new mysqli($host, $user, $password);


 echoCreate database test22;


Instead of echo statements (which would just echo the contents to the  
output, i.e., your browser, you want to assign them to a variable,  
such as:


   $sql = create database test22; use test22;

Then you need to execute the sql statement:

$res = $cxn-query($sql);
if (!$res) {
die(Could not create database test22:  . $cxn-error());
}


 echoCreate table Names2


$sql = create table Names2


 (
  RecordNum Int(11) Primary Key Not null default=1
auto_increment,
  FirstName varchar(10),
  LastName varchar(10),
  Height  decimal(4,1),
  Weight0 decimal(4,1),
  BMI decimal(3,1)
  Date0 date
 );


  ; // to close off the php statement
$res = $cxn-query($sql);
if (!$res) {
die(Could not create table Names2:  . $cxn-error());
}



 echo   Create table Visit2


$sql = create table Visit2


 (
  Indx Int(7) Primary Key Not null auto_increment,
  Weight decimal(4,1) not null,
  StudyDate date not null,
  RecordNum Int(11)
 );


; // again, to close off the php statement
$res = $cxn-query($sql);
if (!$res) {
die(Could not create table Visit2:  . $cxn-error());
}



  $sql= SHOW DATABASES;


This doesn't work in a programmatic setting.

Terminate the database connection:

$cxn-close();


 ?
 /body/html



 I would also like to be able to add data to a table, using PHP,  
which I

can do
 in MySQL as:
 load data infile '/home/ethan/Databases/tester21.dat.' replace  
into table
 Names fields escaped by '\\' terminated by '\t'  lines terminated  
by '\n'

;



That's a specific feature of the mysql program. You'd have to write  
something in php to be able to parse the file and insert the data.  
There are examples all over the net. Then you would need to set up sql  
insert or replace statements to actually get the data into the data  
base using mysqli::query. There are numerous examples of this as well.


Here's one example:

?php

$host = localhost;
$user = root;
$pwd = rootpassword;
$db = test22;
$table = table_to_insert_into;

$cxn = new mysql($host, $user, $pwd, $db);

$filename = tab-delimited.txt;
	$contents = file($filename); // returns the contents of the file into  
an array, one line of file per array


	$columns = explode(\t, $contents[0]); // get the column names from  
the first line of the file


$sql = insert into $table set ;
for ($i=1; $icount($contents) ; $i++) {
$data = explode(\t, $contents[$i]);
$j = 0;
foreach ($columns as $column) {
			$insertdata[] = $column=' . $cxn-real_escape_string($data[$j+ 
+]) . '; // this assumes the column names in the tsv file match the  
column names in your data base table exactly. It also assumes that all  
your data are strings, not numerics.

}
$sql .= implode(,,$insertdata);
$res = $cxn-query($sql);
if (!res) die (Error inserting data:  . $cxn-error());
}
?
htmlheadtitleImported data/title/head
body
pData just imported:/p
table border=1 cellpadding=2px cellspacing=2px
thead
tr style=color: white; background-color: black; text-align: center
?

	$res = $cxn-query(select * from $table limit 1); // get one row  
from table for generating column names

if (!res) die (Query failed for table $table:  . $cxn-error());
$row = $res-fetch_assoc();
foreach ($row as $column = $value) {
echo th . $column . /th;
}
?
/tr
/thead
tbody
?

$res = $cxn-query(select * from $table);
if (!res) die (Query failed for table $table:  . $cxn-error());
while ($row = $res-fetch_assoc()) {
echo tr;
foreach ($row as $column = $value) {
echo td . $value . /td;
}
echo /tr\n;
   

Re: [PHP] Questions from a Newbie

2010-10-17 Thread Tamara Temple

gah, i botched that up.

For the first part, you want the following:

$cxn = new mysql($host, $user, $password);
$res = $cxn-query(create database test22:);
if (!$res) {
die(Failed to create database test22:  . $cxn-error());
}

Then, reopen the connection with the new data base:

$cxn = new mysql($host, $user, $password, test22);

Then the following code will work.


Tamara Temple
-- aka tamouse__
tam...@tamaratemple.com


May you never see a stranger's face in the mirror.

On Oct 17, 2010, at 4:26 PM, Tamara Temple wrote:



On Oct 17, 2010, at 1:22 PM, Ethan Rosenberg wrote:

At 01:41 AM 10/17/2010, Tommy Pham wrote:
 I cannot get the following to work.  In my Firefox [Iceweasel]  
browser, I

 enter the following URL: [w/ the http]


Whenever you get a blank screen running a php application, the place  
to look is the http server's error_log. This is frequently found in / 
var/log/httpd/error_log or /var/log/apache2/error_log. (If your  
system is hosted someplace else, it could very easily be in a  
different place). Typically you need root permission to read this  
file. Tail the file after you run your PHP script to see the most  
recent errors.



 The code  contained in the file CreateNew.php is:

 /*
   *  Create Database test22
   */
   htmlbody
 ?php
 $cxn = mysqli_connect($host,$user,$password);


Better to use the OO approach:

$cxn = new mysqli($host, $user, $password);


 echoCreate database test22;


Instead of echo statements (which would just echo the contents to  
the output, i.e., your browser, you want to assign them to a  
variable, such as:


   $sql = create database test22; use test22;

Then you need to execute the sql statement:

$res = $cxn-query($sql);
if (!$res) {
die(Could not create database test22:  . $cxn-error());
}


 echoCreate table Names2


$sql = create table Names2


 (
  RecordNum Int(11) Primary Key Not null default=1
auto_increment,
  FirstName varchar(10),
  LastName varchar(10),
  Height  decimal(4,1),
  Weight0 decimal(4,1),
  BMI decimal(3,1)
  Date0 date
 );


  ; // to close off the php statement
$res = $cxn-query($sql);
if (!$res) {
die(Could not create table Names2:  . $cxn-error());
}



 echo   Create table Visit2


$sql = create table Visit2


 (
  Indx Int(7) Primary Key Not null auto_increment,
  Weight decimal(4,1) not null,
  StudyDate date not null,
  RecordNum Int(11)
 );


; // again, to close off the php statement
$res = $cxn-query($sql);
if (!$res) {
die(Could not create table Visit2:  . $cxn-error());
}



  $sql= SHOW DATABASES;


This doesn't work in a programmatic setting.

Terminate the database connection:

$cxn-close();


 ?
 /body/html



 I would also like to be able to add data to a table, using PHP,  
which I

can do
 in MySQL as:
 load data infile '/home/ethan/Databases/tester21.dat.' replace  
into table
 Names fields escaped by '\\' terminated by '\t'  lines  
terminated by '\n'

;



That's a specific feature of the mysql program. You'd have to write  
something in php to be able to parse the file and insert the data.  
There are examples all over the net. Then you would need to set up  
sql insert or replace statements to actually get the data into the  
data base using mysqli::query. There are numerous examples of this  
as well.


Here's one example:

?php

$host = localhost;
$user = root;
$pwd = rootpassword;
$db = test22;
$table = table_to_insert_into;

$cxn = new mysql($host, $user, $pwd, $db);

$filename = tab-delimited.txt;
	$contents = file($filename); // returns the contents of the file  
into an array, one line of file per array


	$columns = explode(\t, $contents[0]); // get the column names  
from the first line of the file


$sql = insert into $table set ;
for ($i=1; $icount($contents) ; $i++) {
$data = explode(\t, $contents[$i]);
$j = 0;
foreach ($columns as $column) {
			$insertdata[] = $column=' . $cxn-real_escape_string($data[$j+ 
+]) . '; // this assumes the column names in the tsv file match  
the column names in your data base table exactly. It also assumes  
that all your data are strings, not numerics.

}
$sql .= implode(,,$insertdata);
$res = $cxn-query($sql);
if (!res) die (Error inserting data:  . $cxn-error());
}
?
htmlheadtitleImported data/title/head
body
pData just imported:/p
table border=1 cellpadding=2px cellspacing=2px
thead
tr style=color: white; background-color: black; text-align: center
?

	$res = $cxn-query(select * from $table limit 1); // get one row  
from 

[PHP] Zip files: generate text file in archive on the fly

2010-10-17 Thread Dotan Cohen
I need to provide a download of a zip archive containing three files.
This is fairly straightforward in PHP so long as one is working with
files that already exist. However, I need to customise one of the
files (a simple text file) with the user name and other info before
zipping. I see no mention of this in the fine manual, and even
googling has led me nowhere. Ideas? Am I missing something obvious?

Thanks!

-- 
Dotan Cohen

http://gibberish.co.il
http://what-is-what.com

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



Re: [PHP] Zip files: generate text file in archive on the fly

2010-10-17 Thread Simon J Welsh
Have you considered writing to a temporary file?
On 18/10/2010, at 11:55 AM, Dotan Cohen wrote:

 I need to provide a download of a zip archive containing three files.
 This is fairly straightforward in PHP so long as one is working with
 files that already exist. However, I need to customise one of the
 files (a simple text file) with the user name and other info before
 zipping. I see no mention of this in the fine manual, and even
 googling has led me nowhere. Ideas? Am I missing something obvious?
 
 Thanks!
 
 -- 
 Dotan Cohen
 
 http://gibberish.co.il
 http://what-is-what.com
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 

---
Simon Welsh
Admin of http://simon.geek.nz/

Who said Microsoft never created a bug-free program? The blue screen never, 
ever crashes!

http://www.thinkgeek.com/brain/gimme.cgi?wid=81d520e5e





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



[PHP] Re: Zip files: generate text file in archive on the fly

2010-10-17 Thread Justin Martin

On 10-10-17 03:55 PM, Dotan Cohen wrote:

I need to provide a download of a zip archive containing three files.
This is fairly straightforward in PHP so long as one is working with
files that already exist. However, I need to customise one of the
files (a simple text file) with the user name and other info before
zipping. I see no mention of this in the fine manual, and even
googling has led me nowhere. Ideas? Am I missing something obvious?

Thanks!



The solution to this seems to be as simple as grabbing the contents of 
the file using ZipArchive::getFromName (or equivalent), deleting that 
file in the archive, modifying the contents, then writing the file using 
ZipArchive::addFromString.


Were ZipArchive::getStream able to handle write operations, I imagine 
you could modify it this way, but reading the file in for modification 
is much less issue-laden.


I haven't tested it, but you could also simply try using 
ZipArchive::addFromString without deleting the file first. It may just 
overwrite the file.


Thanks,
Justin Martin

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



[PHP] Re: Fatal error: Allowed memory size of XXXXX bytes exhausted

2010-10-17 Thread Justin Martin

On 10-10-15 04:42 PM, Julien Jabouin wrote:

Hello,

I have an issu with a script launched by cron.

In fact, although i setup php memory_limit to high value (1G or 2Go),
i have the same issue.

By example  with 2G :

Output from command /usr/bin/php5 -d memory_limit=2G -f
/home/test/www/cron.php ..

Fatal error: Allowed memory size of 536870912 bytes exhausted (tried
to allocate 266257 bytes) in
/home/test/www/app/code/local/Ess/M2e/Model/M2eConnector.php on line
423


And with 1G :

Output from command /usr/bin/php5 -d memory_limit=1G -f
/home/test/www/cron.php ..

Fatal error: Allowed memory size of 536870912 bytes exhausted (tried
to allocate 267717 bytes) in
/home/test/www/app/code/local/Ess/M2e/Model/M2eConnector.php on line
423


Result is the same...
Do you know why ?


This is my php version :
/usr/bin/php5 -v
PHP 5.2.6-1+lenny4 with Suhosin-Patch 0.9.6.2 (cli) (built: Nov 22
2009 01:50:58)
Copyright (c) 1997-2008 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2008 Zend Technologies
 with the ionCube PHP Loader v3.3.20, Copyright (c) 2002-2010, by
ionCube Ltd., and
 with Zend Optimizer v3.3.9, Copyright (c) 1998-2009, by Zend Technologies


On a Debian Lenny, 64 bits version.


It would seem that your script is gobbling memory somewhere. Perhaps 
you've entered an infinite loop which is simply tacking additional 
elements onto an array constantly.


Without seeing the script itself, it's hard to say quite what the 
problem might be, but what's evident is that your script is eating memory.


Thanks,
Justin Martin

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



RE: [PHP] Re: strtotime

2010-10-17 Thread Tommy Pham
 -Original Message-
 From: Tamara Temple [mailto:tamouse.li...@gmail.com]
 Sent: Sunday, October 17, 2010 2:33 PM
 To: PHP General
 Subject: Re: [PHP] Re: strtotime
 
 
 On Oct 17, 2010, at 2:34 PM, John Taylor-Johnston wrote:
 
  Here is another nifty piece of code I found. How does this work?
  What is 31556926?
 
 Number of second in a year? (31556926 / (24 * 60 * 60) yields
 365.2421...)
 
 
Your forgot to divide 365.25 days per year ;)


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



Re: [PHP] Questions from a Newbie

2010-10-17 Thread Tommy Pham
On Sun, Oct 17, 2010 at 11:22 AM, Ethan Rosenberg eth...@earthlink.net wrote:



snip


 Tommy -

 Thanks.

 As I stated, I am a newbie.

 1] I am trying to shorten the learning curve by asking some questions, which
 I understand are probably trivial.  A whole MySQLi list of functions at this
 point is to much for me.  I have to break the problem into manageable parts.

 2] It has been my experience that using a GUI does not teach the whole
 subject.  Linux, which is the OS I use cannot be run from a GUI.

 In the code being discussed, I wish to create a database and add two tables.
  I also note a MySQL statement that can be used to add data to an existing
 table, and wish to be able to execute this statement using PHP.

 So, therefore..

 Let us try to answer the following two(2) questions:

 a] What changes [other than moving the simicolons] have to be made to
 correct the code.

That's why I suggested you to read that section regarding the usage of
PHP's MySQL extension.  If you still have problems understanding that
section or if it's a bit too much, I strongly suggest you start
reading the manual from the beginning.  It's obvious you're not very
clear on the syntax of PHP and you jumped right into the middle of
accessing the database and try to manipulate the DB using PHP.

What you need to know is the fundamentals 1st: variable declarations
and assignments, types of variables, basic outputs (such as echo,
print, etc), conditions, loops, etc...  In the official manual, all of
that is covered up to Classes  Objects, not including.  Class 
Objects and there after are for more of PHP5+ and OOP.  When in doubt,
there is always the function reference.


 b] What books can you suggest to help w/ MySQL and PHP?  I already have the
 SQL, MySQL  PHP, and HTML books in the . for Dummies series.  I need
 something with a little more depth and detail.

If you intend to use PHP to access the a DBMS, you need to have a
strong grasp of fundamentals of SQL.  I mean that as beyond  a simple
select statement.  If you already have that and the fundamentals of
PHP, reading that MySQL section I mentioned should give you the
understanding you needed on how to use PHP to access and manipulate
the data from the DB.  One good way to learn to copy the sample codes
from the manual and run it on your development box.   Make some
changes to code after the 1st few runs to see if you're understanding
it correctly and that you should be getting the output from the code
change as you expected based on your understanding of the material you
just read.  Reading any books (hard copy or electronic version) are
good but you won't truly understand and remember how it works unless
you apply that knowledge ASAP, IMO.  Learning for me is reverse
engineering.  That's the fastest way I learn.


 Thanks to all for your excellent help.

 Ethan
 
  Using Debian(sid)
 



Regards,
Tommy

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



Re: [PHP]About Character Set

2010-10-17 Thread Sharl.Jimh.Tsin
oh,it is none of the PHP language's business. you should work on your
Apache Server's Configuration Files.

Best regards,
Sharl.Jimh.Tsin (From China)



2010/10/17 Ashley Sheridan a...@ashleysheridan.co.uk:
 On Sun, 2010-10-17 at 21:56 +0800, 肖晗 wrote:

 There is a download directory(to provide download links) in my site.
 http://vedaclub.org/download/
 Some of the filenames contain Chinese characters, which, however cannot be
 recognized.
 Is there anything I can do to solve problem?

 Thanks in advance!



 The short answer is yes, remove the Chinese characters, however, I
 think you were looking for something a little more automatic?

 If the URL itself is causing the problem, maybe you could use the
 urlencode() and urldecode() functions to make the filename for the URL
 web-safe.

 Another alternative that I've used before is to give each file an entry
 in a DB and use a moniker to identify the file. The DB can handle all
 sorts of extra functions in the future, such as allowing only specific
 users to access a file, storing multiple versions of the same file
 bearing the same name (on the server each version has a unique name, the
 user need only know that they're requesting template.doc, version 3,
 etc) and many other things.

 Thanks,
 Ash
 http://www.ashleysheridan.co.uk




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



Re: [PHP] Questions from a Newbie

2010-10-17 Thread Paul M Foster
On Sun, Oct 17, 2010 at 01:00:44AM -0400, Ethan Rosenberg wrote:

 Dear List -
 
 Here are some questions, which I am sure are trivial, but I am a
 newbie, and cannot find the answers online
 
 I cannot get the following to work.  In my Firefox [Iceweasel]
 browser, I enter the following URL: [w/ the http]
 
  localhost/CreateNew.php All I get is a blank browser screen.
 
 The code  contained in the file CreateNew.php is:
 
 /*
  *  Create Database test22
  */
  htmlbody
 ?php
 $cxn = mysqli_connect($host,$user,$password);
 echoCreate database test22;
 echoCreate table Names2

There's no need to quote $host above. Why your echo statements aren't
showing up possibly indicates the script is aborting before it gets to
them.

In situations like this, check the error logs if possible. If not, break
the problem down into even smaller chunks. Do your connect with MySQL
and then test to see if the connection actually worked. According to the
docs, mysqli_connect() should return an object representing the
connection. So check that first:

if (!is_object($cxn))
echo Not connected!;
else
echo Yep, it connected!;

 (
 RecordNum Int(11) Primary Key Not null default=1 auto_increment,
 FirstName varchar(10),
 LastName varchar(10),
 Height  decimal(4,1),
 Weight0 decimal(4,1),
 BMI decimal(3,1)
 Date0 date
 );
 

As has been mentioned, you're simply echoing these to the page, not
sending them to MySQL. That won't work. You have to feed your SQL
statements to the mysqli_query() function. See the docs.

Also, let me strongly advise you against using upper-and-lower-case
field names in your tables. Others will undoubtedly disagree, but I find
this a maintenance nightmare in the long run. Note that in some SQL
variants (maybe in MySQL as well; I don't recall), you must quote the
field names in queries to preserve their case and make the queries work.

 echo   Create table Visit2
 (
 Indx Int(7) Primary Key Not null auto_increment,
 Weight decimal(4,1) not null,
 StudyDate date not null,
 RecordNum Int(11)
 );
 
 $sql= SHOW DATABASES;

As mentioned elsewhere, this statement won't work in a web context. It
only works from the MySQL console interface. There are other ways to
achieve this in a programming context, but they involve querying the
MySQL meta-tables. 

Also, to those recommending PHPMyAdmin, it ignores the OP's question,
and doesn't help him/her learn anything. It is completely possible to do
what he wants programmatically, and often is done that way while
installing various frameworks, etc. *You're* welcome to use PHPMyAdmin,
but let the OP do it his/her way, and help them along if you can.

Paul

-- 
Paul M. Foster

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