php-general Digest 18 Oct 2010 09:55:34 -0000 Issue 6993
Topics (messages 308768 through 308783):
Re: strtotime
308768 by: John Taylor-Johnston
308769 by: richard gray
308771 by: Tamara Temple
308778 by: Tommy Pham
308782 by: Tamara Temple
308783 by: Richard Quadling
Re: Questions from a Newbie
308770 by: [email protected]
308772 by: Tamara Temple
308773 by: Tamara Temple
308779 by: Tommy Pham
308781 by: Paul M Foster
Zip files: generate text file in archive on the fly
308774 by: Dotan Cohen
308775 by: Simon J Welsh
308776 by: Justin Martin
Re: Fatal error: Allowed memory size of XXXXX bytes exhausted
308777 by: Justin Martin
Re: About Character Set
308780 by: Sharl.Jimh.Tsin
Administrivia:
To subscribe to the digest, e-mail:
[email protected]
To unsubscribe from the digest, e-mail:
[email protected]
To post to the list, e-mail:
[email protected]
----------------------------------------------------------------------
--- Begin Message ---
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: YYYY-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);
--- End Message ---
--- Begin Message ---
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
--- End Message ---
--- Begin Message ---
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...)
--- End Message ---
--- Begin Message ---
> -----Original Message-----
> From: Tamara Temple [mailto:[email protected]]
> 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 ;)
--- End Message ---
--- Begin Message ---
On Oct 17, 2010, at 9:57 PM, Tommy Pham wrote:
-----Original Message-----
From: Tamara Temple [mailto:[email protected]]
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 ;)
well, no i didn't forget, merely pointing out that it equals days in a
year.
--- End Message ---
--- Begin Message ---
On 17 October 2010 20:34, John Taylor-Johnston
<[email protected]> wrote:
> Yaay, I'm 45 now :).
Happy Birthday. ;-)
--
Richard Quadling
Twitter : EE : Zend
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY
--- End Message ---
--- Begin Message ---
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" <[email protected]>
Date: Sun, Oct 17, 2010 19:22
Subject: [PHP] Questions from a Newbie
To: "Tommy Pham" <[email protected]>, <[email protected]>
At 01:41 AM 10/17/2010, Tommy Pham wrote:
> > -----Original Message-----
> > From: Ethan Rosenberg [mailto:[email protected]]
> > Sent: Saturday, October 16, 2010 10:01 PM
> > To: [email protected]
> > 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
> > */
> > <html><body>
> > <?php
> > $cxn = mysqli_connect("$host",$user,$password);
> > echo "Create database test22;"
> > echo "Create table Names2
> > (
> > RecordNum Int(11) Primary Key Not null default=10000
>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
--- End Message ---
--- Begin Message ---
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
> */
> <html><body>
> <?php
> $cxn = mysqli_connect("$host",$user,$password);
Better to use the OO approach:
$cxn = new mysqli($host, $user, $password);
> echo "Create 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());
}
> echo "Create table Names2
$sql = "create table Names2
> (
> RecordNum Int(11) Primary Key Not null default=10000
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; $i<count($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());
}
?>
<html><head><title>Imported data</title></head>
<body>
<p>Data 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";
}
?>
</tbody>
</table>
</body>
</html>
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.
Important, most used mysqli functions:
Creating the database connection: $cxn = new mysqli( host, user,
password, database ); (mysqli::__construct function)
Submitting queries: $result = $cxn->query( sql ); (mysqli::query
function)
Working with results: $row = $result->fetch_assoc(); -- returns an
associative array of a sql select statement result, subsequent calls
return the next row in the result until the results are exhausted.
Syntax errors: $cxn->error() -- reports the mysql error of the last
query.
These will get you started quite well.
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.
mysql(1) is an interactive program that does a lot of things to help
you interact with mysql databases. It's functions are not all
duplicated in the programmatic interface to mysql(i) -- i.e. you have
to write them yourself.
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.
See above
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.
Personally, Dummies books don't provide the necessary information to
actually become proficient at any particular topic.
My personal favourite books are in the O'Reilly catalog, although some
are dated:
- Head First PHP and MySql: http://oreilly.com/catalog/9780596006303/
- PHP Cookbook: http://oreilly.com/catalog/9780596101015/
- Learning PHP, MySQL, and JavaScript: http://oreilly.com/catalog/9780596157135/
- MySQL Cookbook (oreilly.com is currently returning a server error on
this title, unfortunately)
Tamara
--- End Message ---
--- Begin Message ---
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__
[email protected]
"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
> */
> <html><body>
> <?php
> $cxn = mysqli_connect("$host",$user,$password);
Better to use the OO approach:
$cxn = new mysqli($host, $user, $password);
> echo "Create 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());
}
> echo "Create table Names2
$sql = "create table Names2
> (
> RecordNum Int(11) Primary Key Not null default=10000
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; $i<count($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());
}
?>
<html><head><title>Imported data</title></head>
<body>
<p>Data 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";
}
?>
</tbody>
</table>
</body>
</html>
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.
Important, most used mysqli functions:
Creating the database connection: $cxn = new mysqli( host, user,
password, database ); (mysqli::__construct function)
Submitting queries: $result = $cxn->query( sql ); (mysqli::query
function)
Working with results: $row = $result->fetch_assoc(); -- returns an
associative array of a sql select statement result, subsequent calls
return the next row in the result until the results are exhausted.
Syntax errors: $cxn->error() -- reports the mysql error of the last
query.
These will get you started quite well.
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.
mysql(1) is an interactive program that does a lot of things to help
you interact with mysql databases. It's functions are not all
duplicated in the programmatic interface to mysql(i) -- i.e. you
have to write them yourself.
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.
See above
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.
Personally, Dummies books don't provide the necessary information to
actually become proficient at any particular topic.
My personal favourite books are in the O'Reilly catalog, although
some are dated:
- Head First PHP and MySql: http://oreilly.com/catalog/9780596006303/
- PHP Cookbook: http://oreilly.com/catalog/9780596101015/
- Learning PHP, MySQL, and JavaScript: http://oreilly.com/catalog/9780596157135/
- MySQL Cookbook (oreilly.com is currently returning a server error
on this title, unfortunately)
Tamara
--- End Message ---
--- Begin Message ---
On Sun, Oct 17, 2010 at 11:22 AM, Ethan Rosenberg <[email protected]> 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
--- End Message ---
--- Begin Message ---
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
> */
> <html><body>
> <?php
> $cxn = mysqli_connect("$host",$user,$password);
> echo "Create database test22;"
> echo "Create 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=10000 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
--- End Message ---
--- Begin Message ---
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
--- End Message ---
--- Begin Message ---
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
--- End Message ---
--- Begin Message ---
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
--- End Message ---
--- Begin Message ---
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
--- End Message ---
--- Begin Message ---
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 <[email protected]>:
> 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
>
>
>
--- End Message ---