php-general Digest 20 Sep 2009 22:08:10 -0000 Issue 6349

Topics (messages 298195 through 298205):

Re: How to work with embedded mysql from php.
        298195 by: Tommy Pham
        298203 by: Tommy Pham
        298204 by: Tommy Pham

Re: Question: Correcting MySQL's ID colomn when removing an entry
        298196 by: Phpster
        298198 by: tedd
        298201 by: Paul M Foster

Re: Ckeckbox list populated from database
        298197 by: tedd

Random Flash Movies
        298199 by: Gary
        298200 by: Ashley Sheridan
        298202 by: Eddie Drapkin

Creating file name with $variable
        298205 by: Haig Davis

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 ---
--- On Sun, 9/20/09, Nishshanka Sirisena <[email protected]> wrote:

> From: Nishshanka Sirisena <[email protected]>
> Subject: [PHP] How to work with embedded mysql from php.
> To: [email protected]
> Date: Sunday, September 20, 2009, 3:40 AM
> Hi all.
> 
> I am developing a peer to peer application which is written
> in C for windows
> platform and which contains a web interface using php and
> html stuffs. In
> this case for the application I am using embedded mysql
> library as the
> database. Now I have a big problem because I have no Idea
> about How to
> access and manage this embedded mysql database from php.
> 
> Please someone help me to recover from this problem.
> 

Did you try MySQL or MySQLi libs from PHP? What are you using to connect?

--- End Message ---
--- Begin Message ---
>
>From: Nishshanka Sirisena <[email protected]>
>To: Tommy Pham <[email protected]>
>Sent: Sunday, September 20, 2009 7:13:02 AM
>Subject: Re: [PHP] How to work with embedded mysql from php.
>
>>I tried with Mysqli using mysqli_server_init() and mysql_server_end() 
>>functions and I am using Lighttpd as my web server. But when I'm running the 
>>page error log of the lighttpd web server listed following error. And I have 
>>correctly configured lighttpd-php and mysql.
>
>PHP Fatal error:  Call to undefined function mysqli_server_init() in 
>                                                
> C:\lighttpd\htdocs\web\test_db.php on line 27
>
>2009-09-20 09:02:58: (mod_fastcgi.c.1452) 
>>2009-09-20 09:02:58: (connections.c.764) missing cleanup in fastcgi 
>
>I have no previous experience to use this So please can somebody send me a 
>simple implementation of this issue.
>

Nishshanka,

What version and bitness of PHP are you using?  Did you compile it?  Have you 
tried connecting to a non embedded MySQL to ensure the configuration of 
Lighttpd + PHP is correct?  I had breakage of some apps when PHP is configured 
as CGI/FASTCGI and didn't bother using it as such.  Note: If you didn't build 
both, you need to match right Visual Studio version of PHP with Lightthpd.  Mix 
match is very bad...  Official PHP releases are available in VS6 & VS9 only.

What version of embedded MySQL are you using?  Check the phpinfo() to see if 
MySQL/MySQLi is using MySQLnd driver. MySQLnd cannot connect to MySQL 4.1+ 
using old authentication. It may look something like this in phpinfo():
Client API version:  mysqlnd 5.0.5-dev - 081106 - $Revision: 286739 $
(This is my build of PHP-5.3.2-dev x64 running with my build of Apache 2.2.13 
x64 on Win2008 x64.)

You may have to download the PHP source, do some hacking and then compile it 
against embedded MySQL's lib/dll.  Look for HAVE_EMBEDDED_MYSQL in PHP's source 
code files in ext\mysql and ext\mysqli.  After you hack the PHP's source code, 
you should be able to connect the embedded with this or something similar in 
PHP:

$mysql = mysql_init();
mysql_options($mysql, MYSQL_OPT_USE_EMBEDDED_CONNECTION, null);
mysql_real_connect($mysql, null,null,null, "database1", 0,null,0);

Of course, depending on your requirement, the other alternative and easy fix is 
use a non embedded and bind the server to 127.0.0.1.  You'll also don't have to 
deal with the limitations of embedded ;). 
http://dev.mysql.com/doc/refman/5.1/en/libmysqld-restrictions.html

Regards,
Tommy


--- End Message ---
--- Begin Message ---
----- Original Message ----
> From: Tommy Pham <[email protected]>
> To: general php <[email protected]>
> Sent: Sunday, September 20, 2009 9:22:19 AM
> Subject: Re: [PHP] How to work with embedded mysql from php.
> 
> >
> >From: Nishshanka Sirisena 
> >To: Tommy Pham 
> >Sent: Sunday, September 20, 2009 7:13:02 AM
> >Subject: Re: [PHP] How to work with embedded mysql from php.
> >
> >>I tried with Mysqli using mysqli_server_init() and mysql_server_end() 
> functions and I am using Lighttpd as my web server. But when I'm running the 
> page error log of the lighttpd web server listed following error. And I have 
> correctly configured lighttpd-php and mysql.
> >
> >PHP Fatal error:  Call to undefined function mysqli_server_init() in 
> >                                                
> C:\lighttpd\htdocs\web\test_db.php on line 27
> >
> >2009-09-20 09:02:58: (mod_fastcgi.c.1452) 
> >>2009-09-20 09:02:58: (connections.c.764) missing cleanup in fastcgi 
> >
> >I have no previous experience to use this So please can somebody send me a 
> simple implementation of this issue.
> >
> 
> Nishshanka,
> 
> What version and bitness of PHP are you using?  Did you compile it?  Have you 
> tried connecting to a non embedded MySQL to ensure the configuration of 
> Lighttpd 
> + PHP is correct?  I had breakage of some apps when PHP is configured as 
> CGI/FASTCGI and didn't bother using it as such.  Note: If you didn't build 
> both, 
> you need to match right Visual Studio version of PHP with Lightthpd.  Mix 
> match 
> is very bad...  Official PHP releases are available in VS6 & VS9 only.
> 
> What version of embedded MySQL are you using?  Check the phpinfo() to see if 
> MySQL/MySQLi is using MySQLnd driver. MySQLnd cannot connect to MySQL 4.1+ 
> using 
> old authentication. It may look something like this in phpinfo():
> Client API version:  mysqlnd 5.0.5-dev - 081106 - $Revision: 286739 $
> (This is my build of PHP-5.3.2-dev x64 running with my build of Apache 2.2.13 
> x64 on Win2008 x64.)
> 
> You may have to download the PHP source, do some hacking and then compile it 
> against embedded MySQL's lib/dll.  Look for HAVE_EMBEDDED_MYSQL in PHP's 
> source 
> code files in ext\mysql and ext\mysqli.  After you hack the PHP's source 
> code, 
> you should be able to connect the embedded with this or something similar in 
> PHP:
> 
> $mysql = mysql_init();
> mysql_options($mysql, MYSQL_OPT_USE_EMBEDDED_CONNECTION, null);
> mysql_real_connect($mysql, null,null,null, "database1", 0,null,0);
> 
> Of course, depending on your requirement, the other alternative and easy fix 
> is 
> use a non embedded and bind the server to 127.0.0.1.  You'll also don't have 
> to 
> deal with the limitations of embedded ;). 
> http://dev.mysql.com/doc/refman/5.1/en/libmysqld-restrictions.html
> 
> Regards,
> Tommy
> 
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php

I just downloaded  LightTPD (Win32) - SSL 1.4.23-1.  It seems like it was built 
using cygwin and 
"PHP-Support
```````````
- same speed as or faster than apache + mod_php4
- handles various PHP bugs in the FastCGI SAPI
- includes a utility to spawn FastCGI processes (necessary for PHP 4.3.x)"

--- End Message ---
--- Begin Message ---


On Sep 20, 2009, at 3:37 AM, "Parham Doustdar" <[email protected]> wrote:

Hello there,
I'm guessing that when a row in a MySQL table is removed, the ID colomns of the rows which come after that row are not changed. For example:
1
2
3
4

Now, if I want to remove the third rows, the ID colomn would be something like:
1
2
4

I was wondering if there was a way to fix it through a query, so I wouldn't have to use a for statement in PHP to fix it?

Thanks!

--
---
Contact info:
Skype: parham-d
MSN: fire_lizard16 at hotmail dot com
GoogleTalk: [email protected]
Twitter: PD90
email: parham90 at GMail dot com


The quick answer is you don't. it will cause you far more headaches than it's worth. the id is only for uniqueness and linking should have nothing to do with havin any meaning in the data.

Bastien

Sent from my iPod

--- End Message ---
--- Begin Message ---
At 12:07 PM +0430 9/20/09, Parham Doustdar wrote:
Hello there,
I'm guessing that when a row in a MySQL table is removed, the ID colomns of the rows which come after that row are not changed. For example:
1
2
3
4

Now, if I want to remove the third rows, the ID colomn would be something like:
1
2
4

I was wondering if there was a way to fix it through a query, so I wouldn't have to use a for statement in PHP to fix it?

Thanks!

Parham:

This is a common problem with people who are new to databases. The sequence of the index of tables has nothing to do with anything important -- there is no reason to be fearful of, or concerned with, gaps. Gaps are normal and a customary part of the database operation.

I often hear managers/clients say "How do we correct that gap?" -- the simple answer is "We don't" and there is no reason to look upon a gap in a sequence as if it needs correcting.

Now, if you want to display a sequence of records (like a product listing), there is no problem with you reading all the products in your database, sorting them, and listing them in numerical order -- however, that listing has nothing to do with the index of the table.

Similarly, you may even want to list your products in alphabetical order and you can do that too, but again that listing has nothing to do with the index of the table.

So in the end, the index in a table has nothing to do with how you store or list your data -- it simply is an internal thing that the database needs to keep track of unique records.

My advice, allow the database to use the index as it needs and you use the data as you need.

Cheers,

tedd

--
-------
http://sperling.com  http://ancientstones.com  http://earthstones.com

--- End Message ---
--- Begin Message ---
On Sun, Sep 20, 2009 at 12:07:39PM +0430, Parham Doustdar wrote:

> Hello there,
> I'm guessing that when a row in a MySQL table is removed, the ID colomns of 
> the rows which come after that row are not changed. For example:
> 1
> 2
> 3
> 4
> 
> Now, if I want to remove the third rows, the ID colomn would be something 
> like:
> 1
> 2
> 4
> 
> I was wondering if there was a way to fix it through a query, so I wouldn't 
> have to use a for statement in PHP to fix it?
> 

There's nothing to fix here. I assume you're talking about an ID column
which is serialized or "autoincrement". Such columns are not designed to
necessarily be "continuously" numbered. If you remove a row, there is
simply a gap in the sequence. Your application shouldn't care whether
the numbers are continuous or not, though it may care that they are "in
order".

To process such a table, you'd do your query like:

SELECT * FROM mytable ORDER BY id

And then process the results with a foreach or for loop.

I will say, though, that if your application cares about the ordering of
the records, I'd use a different field to implement that, such as
"date_added" or "last_name" or something similar. It's best to assume,
when dealing with autoincrement fields, that the numbers placed in them
are random. They are only designed to be unique within that table, to
allow for easy fetching of a single unique record within the table.
Autoincrement fields are not designed to be used to order the records in
a table.

Paul

-- 
Paul M. Foster

--- End Message ---
--- Begin Message ---
At 9:06 PM -0700 9/19/09, Haig Davis wrote:
Hello List,

I'm relatively new to PHP although I do feel I've got a grasp of the basics. I have used php to draw up numerous selection lists populated from a mysql database and have had no trouble at all.

However when it comes to the same concept yet using HTML check boxes I aM complety stumped. It seems easy but I've been staring at the same problem for hours.

Any hints are greatly appreciated.

Thanks

Haig

Sent from my iPhone

Haig:

This might help:

http://php1.net/b/form-checkbox
http://php1.net/b/form-checkbox1

Cheers,

tedd

PS: I wish I had an iPhone.

--
-------
http://sperling.com  http://ancientstones.com  http://earthstones.com

--- End Message ---
--- Begin Message ---
A question was posted on another board that the poster wanted random flash 
movies to display as the page is reloaded.  I posted the script below and 
said I thought it could be adapted but that the echo would probably need to 
change. Can someone offer some guidance on this?  Thanks

Gary

<?
//Chooses a random number
$num = Rand (1,6);
//Based on the random number, gives a quote
switch ($num)
{
case 1:
echo "";
break;
case 2:
echo "";
break;
case 3:
echo "";
break;
case 4:
echo "";
break;
case 5:
echo "";
break;
case 6:
echo "";
}
?> 



__________ Information from ESET Smart Security, version of virus signature 
database 4441 (20090919) __________

The message was checked by ESET Smart Security.

http://www.eset.com





--- End Message ---
--- Begin Message ---
On Sun, 2009-09-20 at 11:30 -0400, Gary wrote:

> A question was posted on another board that the poster wanted random flash 
> movies to display as the page is reloaded.  I posted the script below and 
> said I thought it could be adapted but that the echo would probably need to 
> change. Can someone offer some guidance on this?  Thanks
> 
> Gary
> 
> <?
> //Chooses a random number
> $num = Rand (1,6);
> //Based on the random number, gives a quote
> switch ($num)
> {
> case 1:
> echo "";
> break;
> case 2:
> echo "";
> break;
> case 3:
> echo "";
> break;
> case 4:
> echo "";
> break;
> case 5:
> echo "";
> break;
> case 6:
> echo "";
> }
> ?> 
> 
> 
> 
> __________ Information from ESET Smart Security, version of virus signature 
> database 4441 (20090919) __________
> 
> The message was checked by ESET Smart Security.
> 
> http://www.eset.com
> 
> 
> 
> 
> 

Call the movies 1.swf, 2.swf it will make it easier. If not, put them in
an associative array. Then, once the random number has been chosen,
output all the code needed for embedding the Flash player, and in-place
of the movie clip name, put your variable. The switch above is
unnecessary, as it will mean a lot of duplication.


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



--- End Message ---
--- Begin Message ---
On Sun, Sep 20, 2009 at 11:33 AM, Ashley Sheridan
<[email protected]> wrote:
> On Sun, 2009-09-20 at 11:30 -0400, Gary wrote:
>
>> A question was posted on another board that the poster wanted random flash
>> movies to display as the page is reloaded.  I posted the script below and
>> said I thought it could be adapted but that the echo would probably need to
>> change. Can someone offer some guidance on this?  Thanks
>>
>> Gary
>>
>> <?
>> //Chooses a random number
>> $num = Rand (1,6);
>> //Based on the random number, gives a quote
>> switch ($num)
>> {
>> case 1:
>> echo "";
>> break;
>> case 2:
>> echo "";
>> break;
>> case 3:
>> echo "";
>> break;
>> case 4:
>> echo "";
>> break;
>> case 5:
>> echo "";
>> break;
>> case 6:
>> echo "";
>> }
>> ?>
>>
>>
>>
>> __________ Information from ESET Smart Security, version of virus signature 
>> database 4441 (20090919) __________
>>
>> The message was checked by ESET Smart Security.
>>
>> http://www.eset.com
>>
>>
>>
>>
>>
>
> Call the movies 1.swf, 2.swf it will make it easier. If not, put them in
> an associative array. Then, once the random number has been chosen,
> output all the code needed for embedding the Flash player, and in-place
> of the movie clip name, put your variable. The switch above is
> unnecessary, as it will mean a lot of duplication.
>
>
> Thanks,
> Ash
> http://www.ashleysheridan.co.uk
>
>
>

What Ash said, something like:

$flashVids = array();
$flashVids[] = '/path/to/movie.swf';
$flashVids[] = '/different/path/movie.swf';
.... //add any amount more

$randomMoviePath = $flashVids[array_rand($flashVids)];

echo "Random flash movie: " . $randomMoviePath;

--- End Message ---
--- Begin Message ---
Good Afternoon All,

Thanks for the help with the checkbox issue the other day.

Todays question: I want to create a filename.php from a variable more specifically the results if a mySQL query I.e. userID + orderNumber = filename. Is this possible? 'cause I've tried every option I can think of and am not winng.

Thanks a ton

Haig

Sent from my iPhone

--- End Message ---

Reply via email to