php-general Digest 1 Aug 2009 14:02:19 -0000 Issue 6261
Topics (messages 296149 through 296163):
Script to Compare Database Structures
296149 by: Matt Neimeyer
296153 by: German Geek
296155 by: Paul M Foster
Re: Can a range be passed to a query?
296150 by: Phpster
296154 by: Paul M Foster
296159 by: Andrew Ballard
Re: Clean break.
296151 by: Ollisso
296152 by: Paul Halliday
Problem: Writing into Files?
296156 by: Parham Doustdar
296161 by: Ollisso
clean url problem .htaccess
296157 by: A.a.k
296160 by: Andrew Ballard
296162 by: A.a.k
296163 by: kranthi
Re: ForEach Range Problems
296158 by: Andrew Ballard
Administrivia:
To subscribe to the digest, e-mail:
php-general-digest-subscr...@lists.php.net
To unsubscribe from the digest, e-mail:
php-general-digest-unsubscr...@lists.php.net
To post to the list, e-mail:
php-gene...@lists.php.net
----------------------------------------------------------------------
--- Begin Message ---
I know I CAN hack something together but I hate to reinvent the wheel.
I want to be able to compare the structure of two different clients
databases that might be on different servers that are firewalled away
from each other. Given the two structures it will list all the SQL
commands needed to make the database structure the same.
In a perfect world on one side you would pull up a PHP page that does
a "generate structure" which would create a downloadable file which
you could then upload to the other system which would then give a
listing of the SQL commands needed to make the local structure match
the uploaded structure.
Thanks in advance...
Matt
--- End Message ---
--- Begin Message ---
have you tried mysqldiff?
++Tim Hinnerk Heuer++
http://www.ihostnz.com (should be .org)
Sponsors welcome to put ads under a linked to page. This is not automated
just yet. Only image, swf or preferably text or short html ads, no
animations please. Price negotiable.
2009/8/1 Matt Neimeyer <m...@neimeyer.org>
> I know I CAN hack something together but I hate to reinvent the wheel.
>
> I want to be able to compare the structure of two different clients
> databases that might be on different servers that are firewalled away
> from each other. Given the two structures it will list all the SQL
> commands needed to make the database structure the same.
>
> In a perfect world on one side you would pull up a PHP page that does
> a "generate structure" which would create a downloadable file which
> you could then upload to the other system which would then give a
> listing of the SQL commands needed to make the local structure match
> the uploaded structure.
>
> Thanks in advance...
>
> Matt
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--- End Message ---
--- Begin Message ---
On Fri, Jul 31, 2009 at 05:38:44PM -0400, Matt Neimeyer wrote:
> I know I CAN hack something together but I hate to reinvent the wheel.
>
> I want to be able to compare the structure of two different clients
> databases that might be on different servers that are firewalled away
> from each other. Given the two structures it will list all the SQL
> commands needed to make the database structure the same.
>
> In a perfect world on one side you would pull up a PHP page that does
> a "generate structure" which would create a downloadable file which
> you could then upload to the other system which would then give a
> listing of the SQL commands needed to make the local structure match
> the uploaded structure.
>
> Thanks in advance...
I don't know what flavor of SQL you're using, but for SQL-compliant
databases, there is an "information_schema" table (I believe that's the
correct name) which contains most or all of the data you need. Query
that table into an array for each server, and compare the arrays.
Here's a query I've used:
SELECT table_name, column_name, data_type, column_default, is_nullable,
character_maximum_length, numeric_precision, numeric_scale FROM
information_schema.columns WHERE table_name = 'tablename' ORDER BY
ordinal_position
This will not tell you the relations between tables, nor which columns
are primary keys, etc. There may be another way to get this out of
information_schema.
Paul
--
Paul M. Foster
--- End Message ---
--- Begin Message ---
On Jul 31, 2009, at 5:24 PM, "Miller, Terion" <tmil...@springfi.gannett.com
> wrote:
I'm still struggling with using ranges... Can they be passed to a
query
somehow...
I have this so far but it pulls nothing:
//Show all with $letter not between "A" and "Z"
if ($
$result = mysql_query($sql) or die(mysql_error());
}
while($row = mysql_fetch_assoc($result)){
$name = $row['name'];
printf(
'<a href="view.php?ID=%s"><b>%s</b><br />%s<br /><br /></a>',
$row['ID'],
$row['name'],
$row['address']
);
}
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
What about
selectedLetter = "#") {
$other = range('0','9');
$sql = "SELECT DISTINCT ID, name, address FROM restaurants WHERE left
(name, 1) between 0 and 9";
Bastien
Sent from my iPod
--- End Message ---
--- Begin Message ---
(Sorry, forgot to send this to the whole list.)
On Fri, Jul 31, 2009 at 05:24:45PM -0400, Miller, Terion wrote:
> I'm still struggling with using ranges... Can they be passed to a query
> somehow...
>
> I have this so far but it pulls nothing:
>
> //Show all with $letter not between "A" and "Z"
>
> if ($selectedLetter = "#") {
Problem #1: The above expression will set $selectedLetter to '#', *not*
check whether $selectedLetter is equal to '#'.
>
> $other = range('0','9');
>
> $sql = "SELECT DISTINCT ID, name, address FROM restaurants WHERE name LIKE
> '$other'";
Problem #2: The range() function returns an array (see documentation).
Echo the $sql variable to screen and you may find that it says:
"SELECT DISTINCT ... LIKE 'Array'"
Try this:
$values = implode(',', $other);
$sql = "SELECT DISTINCT ... LIKE '$values'";
(See documentation for implode().)
<snip>
Paul
--
Paul M. Foster
--- End Message ---
--- Begin Message ---
On Fri, Jul 31, 2009 at 5:55 PM, Phpster<phps...@gmail.com> wrote:
> What about
>
> $sql = "SELECT DISTINCT ID, name, address FROM restaurants WHERE
> left(name, 1) between 0 and 9";
>
>
>
>
> Bastien
>
> Sent from my iPod
You need to wrap the 0 and the 9 in single quotes, or else it returns
everything.
$sql = "SELECT DISTINCT ID, name, address FROM restaurants WHERE
left(name, 1) between '0' and '9'";
Performance could be an issue, also. I tried this and the two versions
I posted on her other thread against a table I have that has just over
8700 rows in it. This version took over 9 times longer to execute.
(Granted, on a table that small it's still 0.0092 seconds compared to
0.0010 seconds. Either of those times is acceptable in my book, but on
a larger table a 9x performance drain could be a serious issue.)
That's because the engine has to examine every row in the table and
calculate left(name, 1) before it can compare that value to the range.
The other versions I posted can simply scan/seek the index within a
range.
Andrew
--- End Message ---
--- Begin Message ---
On Sat, 01 Aug 2009 00:22:21 +0300, Paul Halliday
<paul.halli...@gmail.com> wrote:
Whats the cleanest (I have a really ugly) way to break this:
[21/Jul/2009:00:00:47 -0300]
into:
date=21/jul/2009
time=00:00:47
...
Why not just use regexp ?
For example:
$string = "long text.. multiply lines...
[21/Jul/2009:00:00:47 -0300]
[ 1/Jul/2009:00:00:47 -0300]
[22/Jul/2009:00:00:47 -0300]";
preg_match_all('#\[([ 0-9a-zA-Z/]+):([0-9:]+)
[^]]+\]#',$string,$matches,PREG_SET_ORDER);
print_r($matches);
Output:
Array
(
[0] => Array
(
[0] => [21/Jul/2009:00:00:47 -0300]
[1] => 21/Jul/2009
[2] => 00:00:47
)
[1] => Array
(
[0] => [ 1/Jul/2009:00:00:47 -0300]
[1] => 1/Jul/2009
[2] => 00:00:47
)
[2] => Array
(
[0] => [22/Jul/2009:00:00:47 -0300]
[1] => 22/Jul/2009
[2] => 00:00:47
)
)
--
--- End Message ---
--- Begin Message ---
I was trying to stay away from regex as much as possible due to the
overhead? I might be wrong here.
This script will be parsing a lot of requests/sec. Thousands, maybe
more, which it also needs to toss into a DB. I want to try and keep it
as fast as possible. This is tricky when you don't know what you are
doing :). My coding is limited to hammering away at the search box on
php.net until I get a push in the right direction. It's just a hack
from there.
Using phpster's substr suggestion has already sped this up considerably.
2009/7/31 Ollisso <olli...@fromru.com>:
> On Sat, 01 Aug 2009 00:22:21 +0300, Paul Halliday <paul.halli...@gmail.com>
> wrote:
>
>> Whats the cleanest (I have a really ugly) way to break this:
>>
>> [21/Jul/2009:00:00:47 -0300]
>>
>> into:
>>
>> date=21/jul/2009
>> time=00:00:47
>>
> ...
> Why not just use regexp ?
>
> For example:
>
> $string = "long text.. multiply lines...
> [21/Jul/2009:00:00:47 -0300]
>
> [ 1/Jul/2009:00:00:47 -0300]
>
> [22/Jul/2009:00:00:47 -0300]";
>
>
> preg_match_all('#\[([ 0-9a-zA-Z/]+):([0-9:]+)
> [^]]+\]#',$string,$matches,PREG_SET_ORDER);
>
> print_r($matches);
>
> Output:
> Array
> (
> [0] => Array
> (
> [0] => [21/Jul/2009:00:00:47 -0300]
> [1] => 21/Jul/2009
> [2] => 00:00:47
> )
>
> [1] => Array
> (
> [0] => [ 1/Jul/2009:00:00:47 -0300]
> [1] => 1/Jul/2009
> [2] => 00:00:47
> )
>
> [2] => Array
> (
> [0] => [22/Jul/2009:00:00:47 -0300]
> [1] => 22/Jul/2009
> [2] => 00:00:47
> )
>
> )
>
>
> --
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--- End Message ---
--- Begin Message ---
Hi there,
I've written a counter for my blog, which keeps the count of visitors in a
file. However, when the visitors get too many, it resets to zero. Why?
Here's the piece of code:
[code]
$f = $dir . '/view_counter' .EXT;
$fp = fopen($f, "r");
$count =fgets($fp, 1024);
fclose($fp);
$fw = fopen($f, "w");
$cnew = $count + 1;
$countnew = fputs($fw, $count + 1);
return $cnew;
[/code]
I'm thinking this is caused by two visitors visiting the page at the same time;
but is there a way to fix it, perhaps the reading/writing parameter?
Thanks!
--
---
Contact info:
Skype: parham-d
MSN: fire_lizard16 at hotmail dot com
email: parham90 at GMail dot com
--- End Message ---
--- Begin Message ---
On Sat, 01 Aug 2009 08:20:23 +0300, "Parham Doustdar" <parha...@gmail.com>
wrote:
Hi there,
I've written a counter for my blog, which keeps the count of visitors in
a file. However, when the visitors get too many, it resets to zero. Why?
Here's the piece of code:
[code]
$f = $dir . '/view_counter' .EXT;
$fp = fopen($f, "r");
$count =fgets($fp, 1024);
fclose($fp);
$fw = fopen($f, "w");
$cnew = $count + 1;
$countnew = fputs($fw, $count + 1);
return $cnew;
[/code]
I'm thinking this is caused by two visitors visiting the page at the
same time; but is there a way to fix it, perhaps the reading/writing
parameter?
Thanks!
Check:
http://www.php.net/flock
--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
--- End Message ---
--- Begin Message ---
Hi
I'm trying to use clean urls in my application:
lets say convert http://mysite/article.php?id=3 to
http://mysite/article/3/
my problem is to use /article act as it was /article.php
here is mt .htacess :
<FilesMatch "^article$">
ForceType application/x-httpd-php
</FilesMatch>
on php code parsing string from $_SERVER['PHP_SELF'] to get id out.
this one works if i use article.php (http://mysite/article.php/3/ works)
but i want to use /article without php extention. is there a way around?
--- End Message ---
--- Begin Message ---
On Sat, Aug 1, 2009 at 2:11 AM, A.a.k<blue...@gmail.com> wrote:
> Hi
> I'm trying to use clean urls in my application:
> lets say convert http://mysite/article.php?id=3 to
> http://mysite/article/3/
> my problem is to use /article act as it was /article.php
> here is mt .htacess :
> <FilesMatch "^article$">
> ForceType application/x-httpd-php
> </FilesMatch>
> on php code parsing string from $_SERVER['PHP_SELF'] to get id out.
>
> this one works if i use article.php (http://mysite/article.php/3/ works)
> but i want to use /article without php extention. is there a way around?
>
Look up mod_rewrite.
Andrew
--- End Message ---
--- Begin Message ---
what if I don't have access to server to enable mod_rewrite like a hosting,
is there anyway to work around?
just don't want to build entire website and finally can't get a hosting to
enable mod_rewrite for me.
"Andrew Ballard" <aball...@gmail.com> wrote in message
news:b6023aa40907312352j405778fevd0c38315c3983...@mail.gmail.com...
On Sat, Aug 1, 2009 at 2:11 AM, A.a.k<blue...@gmail.com> wrote:
Hi
I'm trying to use clean urls in my application:
lets say convert http://mysite/article.php?id=3 to
http://mysite/article/3/
my problem is to use /article act as it was /article.php
here is mt .htacess :
<FilesMatch "^article$">
ForceType application/x-httpd-php
</FilesMatch>
on php code parsing string from $_SERVER['PHP_SELF'] to get id out.
this one works if i use article.php (http://mysite/article.php/3/ works)
but i want to use /article without php extention. is there a way around?
Look up mod_rewrite.
Andrew
--- End Message ---
--- Begin Message ---
mod_rewrite is the best solution available to your case. more over if
you are sure that your host supports .htaccess, there is very little
chance that they will block mod rewrite alone. you can confirm that by
phpinfo. look in apache2handler-> Loaded Modules section (this does
not tell you if .htaccess is enabled/disabled)
but in the worst case try using $_SERVER['REQUEST_URI'] instead of
$_SERVER['PHP_SELF'].
in either case you cannot do this with .htaccess disabled.
--- End Message ---
--- Begin Message ---
On Fri, Jul 31, 2009 at 4:51 PM, Miller,
Terion<tmil...@springfi.gannett.com> wrote:
> //Show all restaurants that start with $letter not
> between "A" and "Z"
>
> $other = ctype_digit($letter);
>
> foreach(range('0','9') as $other) {
>
> $sql = "SELECT DISTINCT ID, name, address
> FROM restaurants
> WHERE name LIKE '{$other}%' ";
>
> $result = mysql_query($sql) or die(mysql_error());
>
> while($row = mysql_fetch_assoc($result)){
>
> $name = $row['name'];
>
> printf(
> '<a href="view.php?ID=%s"><b>%s</b><br />%s'
> . '<br /><br /></a>',
> $row['ID'],
> $row['name'],
> $row['address']
> );
> }
> }
Why are you running 10 individual queries to search for restaurants
whose name begins with a number?
There are (at least) two simple, sargable alternatives available that
will work in MySQL to do the work in one shot:
SELECT DISTINCT ID, name, address
FROM restaurants
WHERE name LIKE '0%'
OR name LIKE '1%'
OR name LIKE '2%'
OR name LIKE '3%'
OR name LIKE '4%'
OR name LIKE '5%'
OR name LIKE '6%'
OR name LIKE '7%'
OR name LIKE '8%'
OR name LIKE '9%'
(It can use an index on the `name` column and it works, but it's
pretty verbose. Performance might suffer a little if it involves a
table scan because of the OR's, but I'm not sure about that.)
SELECT DISTINCT ID, name, address
FROM restaurants
WHERE name >= '0' AND name < 'A';
(Its a lot shorter because it takes advantage of string collation. Any
string that begins with the character '0' will be greater than (or
equal if the string is exactly '0') than '0'.)
Also, if your table is set up correctly, you do not need the DISTINCT
keyword in your query. Each restaurant should appear exactly once in
the `restaurants` table.
And just for fun... do you have any restaurants in your list whose
name begins with a punctuation mark or some other non-alphanumeric
character? :-)
Andrew
--- End Message ---