[PHP-DB] php5/MySQL 4.1.1 connection error

2004-02-04 Thread kengaun
Hi,

I am testing to use php5.0.0b3 and connect to MySQL 4.1.1 encountered
connection problem:-

?php
$link = mysqli_connect(localhost, purct, prcyct,purct)
or die(Could not connect:  . mysql_error());
echo Connected successfully;
mysql_close($link);
?


Error message:
---
[04-Feb-2004 14:45:07] PHP Fatal error:  Call to undefined function
mysql_connect() in D:\Purct\New1x.php on line 1

Please help to advise what went wrong ?

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



[PHP-DB] Re: Subject: multiple fields all unique?

2004-02-04 Thread Neil Smth
Jason - you posted this a 5 weeks ago and received several answers.
http://www.phpdiscuss.com/article.php?id=32225group=php.db
You say you have written your own code, but you have not attached it.

As Peter said, the key is probably to declare those columns unique then 
allow the database to determine whether to change those entries using 
REPLACE INTO not INSERT INTO.

Please do not keep re-posting the same problem. Instead, state what you 
tried, how you tried to debug it, and why it didn't work. Then maybe 
somebody will offer to spend more time on your problem, or offer to do it 
for a small fee ;-)

At 07:18 04/02/2004 +, you wrote:
Message-ID: [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Date: Tue, 03 Feb 2004 12:49:44 -0700
From: Jas [EMAIL PROTECTED]
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit
Subject: multiple fields all unique?
I am running into a problem and I have yet to find an elegant solution for it.

I have three fields in a database that cannot have duplicates of these 
particular fields.

+--+---++
| hostname | mac   | ip |
+--+---++
| pmac-1   | 00:30:65:6c:ea:cc | 128.110.22.15  |
+--+---++
| pmac-2   | 00:30:65:6c:e0:cc | 128.110.22.16  |
+--+---++
Now I have a simple form that opens up a record and allows users to modify 
2 of the 3 fields, mac  ip.

In order for the user to save the record and overwrite the current 
contents of the database I first need to do a check to see if any of the 2 
fields being updated match an existing record.

For example say the user modifies the ip field from 128.110.22.15 to 
128.110.22.16, because there is an entry that matches that change the 
record does not update, or vice versa for the mac fields.

Has anyone every performed such a feat as to check for matching fields 
before updating?  And if so could you show me some code that used to 
accomplish this.  I have written my own but the if - else statements are 
getting ridiculous.

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


Re: [PHP-DB] multiple fields all unique?

2004-02-04 Thread Jas
For this table to create 3 unique keys I did the following, in case it 
helps someone else out.
+--+--+--+-+-++
| Field| Type | Null | Key | Default | Extra  |
+--+--+--+-+-++
| id   | int(11)  |  | PRI | NULL| auto_increment |
| hostname | varchar(100) |  | | ||
| mac  | varchar(100) |  | | ||
| ip   | varchar(100) |  | | ||
| vlan | varchar(100) |  | | ||
+--+--+--+-+-++

UPDATE TABLE hosts ADD UNIQUE mac (mac);
UPDATE TABLE hosts ADD UNIQUE hostname (hostname);
UPDATE TABLE hosts ADD UNIQUE ip (ip);
+--+--+--+-+-++
| Field| Type | Null | Key | Default | Extra  |
+--+--+--+-+-++
| id   | int(11)  |  | PRI | NULL| auto_increment |
| hostname | varchar(100) |  | UNI | ||
| mac  | varchar(100) |  | UNI | ||
| ip   | varchar(100) |  | UNI | ||
| vlan | varchar(100) |  | | ||
+--+--+--+-+-++
Now I have used the following to check if duplicate records exist before 
updating:

?php
// Try and update with posted fields form html form
$update = mysql_query(UPDATE hosts SET hostname='$_POST[hostname]', 
mac='$_POST[mac]', ip='$_POST[ip]', vlan='$_POST[vlan]' WHERE 
id='$_SESSION[id]',$db);
$rows = mysql_affected_rows();

// Check results of operation
if($rows == 0) {
  echo No matching records found;
} else {
  echo Matching records found; }
Hope this helps anyone else, and thanks for the tip on MySQL's UNIQUE 
field, wish I would have known it sooner, I wouldn't be so pissed off 
from frustration.
Jas

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


Re: [PHP-DB] multiple fields all unique? [almost solved]

2004-02-04 Thread Jas
Jas wrote:

For this table to create 3 unique keys I did the following, in case it 
helps someone else out.
+--+--+--+-+-++
| Field| Type | Null | Key | Default | Extra  |
+--+--+--+-+-++
| id   | int(11)  |  | PRI | NULL| auto_increment |
| hostname | varchar(100) |  | | ||
| mac  | varchar(100) |  | | ||
| ip   | varchar(100) |  | | ||
| vlan | varchar(100) |  | | ||
+--+--+--+-+-++

UPDATE TABLE hosts ADD UNIQUE mac (mac);
UPDATE TABLE hosts ADD UNIQUE hostname (hostname);
UPDATE TABLE hosts ADD UNIQUE ip (ip);
+--+--+--+-+-++
| Field| Type | Null | Key | Default | Extra  |
+--+--+--+-+-++
| id   | int(11)  |  | PRI | NULL| auto_increment |
| hostname | varchar(100) |  | UNI | ||
| mac  | varchar(100) |  | UNI | ||
| ip   | varchar(100) |  | UNI | ||
| vlan | varchar(100) |  | | ||
+--+--+--+-+-++
Now I have used the following to check if duplicate records exist before 
updating:

?php
// Try and update with posted fields form html form
$update = mysql_query(UPDATE hosts SET hostname='$_POST[hostname]', 
mac='$_POST[mac]', ip='$_POST[ip]', vlan='$_POST[vlan]' WHERE 
id='$_SESSION[id]',$db);
$rows = mysql_affected_rows();

// Check results of operation
if($rows == 0) {
  echo No matching records found;
} else {
  echo Matching records found; }
Hope this helps anyone else, and thanks for the tip on MySQL's UNIQUE 
field, wish I would have known it sooner, I wouldn't be so pissed off 
from frustration.
Jas
Sorry, but now I have one more question about finding the exact field 
for a duplicate entry...

for instance, say you change the mac and hostname and there is a record 
in the database with the same mac string, how can I flag the field that 
matched from the 3?
Thanks,
jas

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


[PHP-DB] apache/php/mysql - guarenteed DB transaction

2004-02-04 Thread whynotpizza

Hi all.

Question on running in a config with Apache2,PHP 4.3.4,MySQL 4.0.17 running
on Linux Redhat 9.0.

Basically I want to make sure that a DB insert or update is guarenteed to
complete.

So if a user hits submit on a webpage, the transaction under the hood
completes, no matter if the user hits cancel or his browser dies or
whatever. (Not sure how to even test this condition, but I know it will
happen)

Below is a sample of my PHP which does one thing, simple insert into mysql. 

I am using MyISAM table types, and would like to maintain this if possible.

Any help or pointers would be greatly appreciated.



David
[EMAIL PROTECTED]



?php // mysqltest.php

// Main Variables
$dbhost = localhost; 
$dbuser = user;
$dbpass = pass;  
$dbname = test;

// open persistent DB connection
$dbcnx = @mysql_pconnect($dbhost, $dbuser, $dbpass) 
or die(The site database appears to be down.); 
if ($db!= and [EMAIL PROTECTED]($db)) 
die(The site database is unavailable.); 

// Open DB Persistent Connection
$dbcnx = dbPConnect(); 
// Execute check against database
mysql_select_db($dbname, $dbcnx);

// Create SQL
$sql = INSERT INTO mytable SET field1='update to field1',field2='update to
field2';

//
// Execute SQL
//
$result = mysql_query($sql); // $result = 1 if success

if ($result == '1') { echo Finished with DB insert;
  }
  else { echo Failed.;
  }

? 

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



Re: [PHP-DB] apache/php/mysql - guarenteed DB transaction

2004-02-04 Thread Matt Matijevich
snip
So if a user hits submit on a webpage, the transaction under the hood
completes, no matter if the user hits cancel or his browser dies or
whatever. (Not sure how to even test this condition, but I know it
will
happen)
/snip

Once php has the request, hitting cancel on the browser or a browser
dying will not stop the php script from executing all the way through.

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



Re: [PHP-DB] apache/php/mysql - guarenteed DB transaction

2004-02-04 Thread Jason Wong
On Wednesday 04 February 2004 23:46, Matt Matijevich wrote:

 Once php has the request, hitting cancel on the browser or a browser
 dying will not stop the php script from executing all the way through.

Actually whether the script runs through to completion depends on the 
'ignore_user_abort' setting.

-- 
Jason Wong - Gremlins Associates - www.gremlins.biz
Open Source Software Systems Integrators
* Web Design  Hosting * Internet  Intranet Applications Development *
--
Search the list archives before you post
http://marc.theaimsgroup.com/?l=php-db
--
/*
I don't care who does the electing as long as I get to do the nominating.
-- Boss Tweed
*/

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



Re: [PHP-DB] apache/php/mysql - guarenteed DB transaction

2004-02-04 Thread Matt Matijevich
snip
Actually whether the script runs through to completion depends on the 
'ignore_user_abort' setting.
/snip

wow, guess you learn something everyday.

wish I would have known about that when I wrote a php script with some
terrible (lots of joins, just poorly designed) queries that took down my
webserver :(

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



[PHP-DB] PEAR DB 1.6.0RC4 released. please test.

2004-02-04 Thread Daniel Convissor
Hi Folks:

I just released version 1.6.0RC4 of PEAR DB.  Several things have been
fixed since RC1 which is included with the latest PHP RC release.  Also,
if you're using 1.5.0 variants or earlier, definitely check out the new
version for loads of enhancements and way fewer bugs.

I've also spent a bunch of time documenting the new functionality and
fixing the old docs.  Most of the changes are already viewable on the PEAR
website and most of the remaining improvements should be in place when the
docs get rebuilt Sunday around 12pm UTC.

So, please download the package and test it out as well as read the
documentation.  Please file bug reports if stuff doesn't work or is
unclear.

Download:http://pear.php.net/get/DB-1.6.0RC4.tgz
Manual:  http://pear.php.net/manual/en/package.database.php
Report Bugs: http://pear.php.net/bugs/report.php?package=DB
Home Page:   http://pear.php.net/package/DB

Enjoy,

--Dan

PS:  I'm not on the list.  Just posting this as an announcement.

-- 
 T H E   A N A L Y S I S   A N D   S O L U T I O N S   C O M P A N Y
data intensive web and database programming
http://www.AnalysisAndSolutions.com/
 4015 7th Ave #4, Brooklyn NY 11232  v: 718-854-0335 f: 718-854-0409

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



Re: [PHP-DB] multiple fields all unique? [almost solved]

2004-02-04 Thread Jas
If I do this statement:
mysql_query(UPDATE hosts SET hostname=\$_POST[hostname]\, 
mac=\$_POST[mac]\, ip=\$_POST[ip]\, vlan=\$_POST[vlan]\ WHERE 
id=\$_SESSION[id]\,$db)or die(mysql_error() . mysql_errno());

I get this error:
Duplicate entry '128.110.22.139' for key 41062
I have tried using these types of checks with no success:
$update = mysql_query(UPDATE hosts SET hostname=\$_POST[hostname]\, 
mac=\$_POST[mac]\, ip=\$_POST[ip]\, vlan=\$_POST[vlan]\ WHERE 
id=\$_SESSION[id]\,$db)or die(mysql_error() . mysql_errno());
$rows = mysql_affected_rows();
  while($match = mysql_fetch_assoc($update)) {
echo $match[hostname];
echo $match[mac];
echo $match[ip]; }
if($rows == 0) {
  echo update worked;
} else {
  echo update didn't work; }

And...
while($match = mysql_fetch_object($update)) {
And..
while($match = mysql_fetch_array($update)) {
So far everything I have tried will not allow me to find the exact field 
and contents of a record that matches an existing record in the 
database.  See below for details on database structure etc.
Any help is appreciated,
jas

Jas wrote:

Jas wrote:

For this table to create 3 unique keys I did the following, in case it 
helps someone else out.
+--+--+--+-+-++
| Field| Type | Null | Key | Default | Extra  |
+--+--+--+-+-++
| id   | int(11)  |  | PRI | NULL| auto_increment |
| hostname | varchar(100) |  | | ||
| mac  | varchar(100) |  | | ||
| ip   | varchar(100) |  | | ||
| vlan | varchar(100) |  | | ||
+--+--+--+-+-++

UPDATE TABLE hosts ADD UNIQUE mac (mac);
UPDATE TABLE hosts ADD UNIQUE hostname (hostname);
UPDATE TABLE hosts ADD UNIQUE ip (ip);
+--+--+--+-+-++
| Field| Type | Null | Key | Default | Extra  |
+--+--+--+-+-++
| id   | int(11)  |  | PRI | NULL| auto_increment |
| hostname | varchar(100) |  | UNI | ||
| mac  | varchar(100) |  | UNI | ||
| ip   | varchar(100) |  | UNI | ||
| vlan | varchar(100) |  | | ||
+--+--+--+-+-++
Now I have used the following to check if duplicate records exist 
before updating:

?php
// Try and update with posted fields form html form
$update = mysql_query(UPDATE hosts SET hostname='$_POST[hostname]', 
mac='$_POST[mac]', ip='$_POST[ip]', vlan='$_POST[vlan]' WHERE 
id='$_SESSION[id]',$db);
$rows = mysql_affected_rows();

// Check results of operation
if($rows == 0) {
  echo No matching records found;
} else {
  echo Matching records found; }
Hope this helps anyone else, and thanks for the tip on MySQL's UNIQUE 
field, wish I would have known it sooner, I wouldn't be so pissed off 
from frustration.
Jas
Sorry, but now I have one more question about finding the exact field 
for a duplicate entry...

for instance, say you change the mac and hostname and there is a record 
in the database with the same mac string, how can I flag the field that 
matched from the 3?
Thanks,
jas
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] multiple fields all unique?

2004-02-04 Thread John W. Holmes
From: Jas [EMAIL PROTECTED]

 Now I have used the following to check if duplicate records exist before
 updating:

 ?php
 // Try and update with posted fields form html form
 $update = mysql_query(UPDATE hosts SET hostname='$_POST[hostname]',
 mac='$_POST[mac]', ip='$_POST[ip]', vlan='$_POST[vlan]' WHERE
 id='$_SESSION[id]',$db);
 $rows = mysql_affected_rows();

 // Check results of operation
 if($rows == 0) {
echo No matching records found;
 } else {
echo Matching records found; }

 Hope this helps anyone else, and thanks for the tip on MySQL's UNIQUE
 field, wish I would have known it sooner, I wouldn't be so pissed off
 from frustration.

One thing to note here, also... if you update a row with the same exact
information, mysql_affected_rows() will return zero. So, even though a row
is matched and updated, nothing is really affected. Not sure if that
matters here, but something to be aware of.

---John Holmes...

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



Re: [PHP-DB] multiple fields all unique? [almost solved]

2004-02-04 Thread John W. Holmes
From: Jas [EMAIL PROTECTED]

 for instance, say you change the mac and hostname and there is a record
 in the database with the same mac string, how can I flag the field that
 matched from the 3?

Your update will actually fail in the case, so you need to catch the error
with mysql_error() (and maybe mysql_errno()) and examine it to see which
key (or index) was matched (a unique column is an index).

When you update the table with an existing mac value, the error will be
similar to Duplicate value for Key XX where XX is what key was duplicated.
I can't remember if the keys start at zero or one, but your ID column will
be the first key, then mac, hostname, and finally ip (in the order they were
created).

So, if you examine the result of mysql_error() and it say duplicate for key
2, then the mac column was duplicated.

Although this sounds a little harder than doing a SELECT prior to and just
comparing values, it lets you do this with just a single query and only have
extra processing upon errors instead of every single update.

If you need a working example, let me know.

---John Holmes...

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



Re: [PHP-DB] multiple fields all unique? [almost solved]

2004-02-04 Thread Jas
John W. Holmes wrote:
[snip]
When you update the table with an existing mac value, the error will be
similar to Duplicate value for Key XX where XX is what key was duplicated.
I can't remember if the keys start at zero or one, but your ID column will
be the first key, then mac, hostname, and finally ip (in the order they were
created).
So, if you examine the result of mysql_error() and it say duplicate for key
2, then the mac column was duplicated.
Although this sounds a little harder than doing a SELECT prior to and just
comparing values, it lets you do this with just a single query and only have
extra processing upon errors instead of every single update.
[/snip]

Your right, I am able to see which record matches (not the record I am 
updating) I think you just answered my question by stating that

 Although this sounds a little harder than doing a SELECT prior to and 
 just
 comparing values, it lets you do this with just a single query and
 only have
 extra processing upon errors instead of every single update.

I suppose that is what I am going to have to do before doing the update. 
 If you know of a different method please elaborate.
thanks again,
Jas

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


Re: [PHP-DB] multiple fields all unique? [almost solved]

2004-02-04 Thread John W. Holmes
From: Jas [EMAIL PROTECTED]

 If I do this statement:
 mysql_query(UPDATE hosts SET hostname=\$_POST[hostname]\,
 mac=\$_POST[mac]\, ip=\$_POST[ip]\, vlan=\$_POST[vlan]\ WHERE
 id=\$_SESSION[id]\,$db)or die(mysql_error() . mysql_errno());

 I get this error:
 Duplicate entry '128.110.22.139' for key 41062

 I have tried using these types of checks with no success:
 $update = mysql_query(UPDATE hosts SET hostname=\$_POST[hostname]\,
 mac=\$_POST[mac]\, ip=\$_POST[ip]\, vlan=\$_POST[vlan]\ WHERE
 id=\$_SESSION[id]\,$db)or die(mysql_error() . mysql_errno());
 $rows = mysql_affected_rows();
while($match = mysql_fetch_assoc($update)) {
  echo $match[hostname];
  echo $match[mac];
  echo $match[ip]; }
 if($rows == 0) {
echo update worked;
 } else {
echo update didn't work; }

 And...
 while($match = mysql_fetch_object($update)) {

 And..
 while($match = mysql_fetch_array($update)) {

 So far everything I have tried will not allow me to find the exact field
 and contents of a record that matches an existing record in the
 database.  See below for details on database structure etc.
 Any help is appreciated,

You're not going to be able to fetch anything from the result set because
you're excuting an UPDATE query, not a SELECT.

You also do not want to die() when the query fails, otherwise you won't be
able to react to the error. Execute the query, then check mysql_error() for
a value. If it contains a value, then the query failed more than likely
because of a duplicate key.

The format of the error message is always the same, Duplicate entry ''
for key , where  is the value that was duplicated and  is the
key number. It looks like key 41062 is the IP column. So you can look for
the 41062 and display a message about duplicate IP.

If it were me, I'd just match the value between single quotes, and echo a
message such as Duplicate value . The difference between a mac, ip,
and hostname are pretty obvious, so you don't really _have_ to tell the user
which one it is.

---John Holmes...

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



Re: [PHP-DB] multiple fields all unique? [almost solved]

2004-02-04 Thread Jas
[snip]
You're not going to be able to fetch anything from the result set because
you're excuting an UPDATE query, not a SELECT.
You also do not want to die() when the query fails, otherwise you won't be
able to react to the error. Execute the query, then check mysql_error() for
a value. If it contains a value, then the query failed more than likely
because of a duplicate key.
[snip]

Well looks like I need to brush up on my php - mysql functions.  =)
For anyone that has been following this thread here is a simple way to 
catch the duplicate and show the user the contents:

?php
$update = mysql_query(UPDATE hosts SET hostname=\$_POST[hostname]\, 
mac=\$_POST[mac]\, ip=\$_POST[ip]\, vlan=\$_POST[vlan]\ WHERE 
id=\$_SESSION[id]\,$db);
$rows = mysql_affected_rows();
 if([EMAIL PROTECTED]($update)) {
  echo No match found;
 } else {
  echo Match found;
  $error = preg_match(/^[']$/,mysql_errno($update));
  $sql = mysql_query(select * from hosts where id = $error)
while($x = mysql_fetch_array($sql)) {
  list($id,$host,$mac,$ip,$vlan) = $x; }
 }
?

Might want to check the preg_match string to look for everything between 
 ' and ' but other than that you should be able to list the record that 
your update statement is having a problem with.
HTH
Jas

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


RE: [PHP-DB] apache/php/mysql - guarenteed DB transaction

2004-02-04 Thread whynotpizza

Thanks guys, this is great info.

One last thought, 

Suppose I have several DB transactions that I want to treat as 1 logical
transaction that I need to complete guarenteed.

For instance, an INSERT to one table, and a DELETE to another, and an UPDATE
to a third. All need to complete once a user selects submit.

What's the best approach to this scenario?

Thanks in advance for the help,


David



-Original Message-
From: Matt Matijevich [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, February 04, 2004 11:17 AM
To: [EMAIL PROTECTED]; [EMAIL PROTECTED]
Subject: Re: [PHP-DB] apache/php/mysql - guarenteed DB transaction


snip
Actually whether the script runs through to completion depends on the 
'ignore_user_abort' setting.
/snip

wow, guess you learn something everyday.

wish I would have known about that when I wrote a php script with some
terrible (lots of joins, just poorly designed) queries that took down my
webserver :(

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

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



RE: [PHP-DB] apache/php/mysql - guarenteed DB transaction

2004-02-04 Thread Matt Matijevich
snip
Suppose I have several DB transactions that I want to treat as 1
logical
transaction that I need to complete guarenteed.

For instance, an INSERT to one table, and a DELETE to another, and an
UPDATE
to a third. All need to complete once a user selects submit.

What's the best approach to this scenario?
/snip

this is the pseudo code i would use:

start the transaction
INSERT
DELETE
UPDATE
if everything is ok, commit, else rollback

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



Res: [PHP-DB] apache/php/mysql - guarenteed DB transaction

2004-02-04 Thread Ricardo Oliveira








Hi,
I had a similar problem andI solved it using transations, but I had to use InnoDB table types...

Regards,
Ricardo

---Mensagem original---


De: whynotpizza
Data: 02/04/04 15:33:37
Para: [EMAIL PROTECTED]
Assunto: [PHP-DB] apache/php/mysql - guarenteed DB transaction

Hi all.

Question on running in a config with Apache2,PHP 4.3.4,MySQL 4.0.17 running
on Linux Redhat 9.0.

Basically I want to make sure that a DB insert or update is guarenteed to
complete.

So if a user hits submit on a webpage, the transaction under the hood
completes, no matter if the user hits cancel or his browser dies or
whatever. (Not sure how to even test this condition, but I know it will
happen)

Below is a sample of my PHP which does one thing, simple insert into mysql.

I am using MyISAM table types, and would like to maintain this if possible.

Any help or pointers would be greatly appreciated.



 David
 [EMAIL PROTECTED]



?php // mysqltest.php

// Main Variables
$dbhost = "localhost";
$dbuser = "user";
$dbpass = "pass";
$dbname = "test";

// open persistent DB connection
$dbcnx = @mysql_pconnect($dbhost, $dbuser, $dbpass)
or die("The site database appears to be down.");
if ($db!="" and [EMAIL PROTECTED]($db))
die("The site database is unavailable.");

// Open DB Persistent Connection
$dbcnx = dbPConnect();
// Execute check against database
mysql_select_db($dbname, $dbcnx);

// Create SQL
$sql = "INSERT INTO mytable SET field1='update to field1',field2='update to
field2'";

//
// Execute SQL
//
$result = mysql_query($sql); // $result = 1 if success

if ($result == '1') { echo "Finished with DB insert";
}
else { echo "Failed.";
}

?

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









 IncrediMail - O mundo do correio eletrĂ´nico finalmente desenvolveu-se - Clique aqui

Res: RE: [PHP-DB] apache/php/mysql - guarenteed DB transaction

2004-02-04 Thread Ricardo Oliveira






You should use

set autocommit = 0;
start transaction;
insert code;
delete code;
update code;

commit or rollback depending on the result;

To do all this I had to use InnoDB table types.

Sorry, my english is quite pour,

Best regards,
Ricardo

---Mensagem original---


De: whynotpizza
Data: 02/04/04 20:39:13
Para: 'Matt Matijevich'; [EMAIL PROTECTED]; [EMAIL PROTECTED]
Assunto: RE: [PHP-DB] apache/php/mysql - guarenteed DB transaction

Thanks guys, this is great info.

One last thought,

Suppose I have several DB transactions that I want to treat as 1 logical
transaction that I need to complete guarenteed.

For instance, an INSERT to one table, and a DELETE to another, and an UPDATE
to a third. All need to complete once a user selects submit.

What's the best approach to this scenario?

Thanks in advance for the help,


 David



-Original Message-
From: Matt Matijevich [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, February 04, 2004 11:17 AM
To: [EMAIL PROTECTED]; [EMAIL PROTECTED]
Subject: Re: [PHP-DB] apache/php/mysql - guarenteed DB transaction


snip
Actually whether the script runs through to completion depends on the
'ignore_user_abort' setting.
/snip

wow, guess you learn something everyday.

wish I would have known about that when I wrote a php script with some
terrible (lots of joins, just poorly designed) queries that took down my
webserver :(

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

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









 IncrediMail - O mundo do correio eletrĂ´nico finalmente desenvolveu-se - Clique aqui

[PHP-DB] Re: php5/MySQL 4.1.1 connection error

2004-02-04 Thread kengaun
Hi ALL,
MySql support is not bundled with PHP 5.0.0

I have managed to connect to MySQL after I have copied the new dll
libmySQL.dll(in php/dlls) folder to c:\windows\system32
And modified the php.ini as per below.
In php.ini
; Directory in which the loadable extensions (modules) reside.
extension_dir = c:\php\extensions
;;
; Dynamic Extensions ;
;;
extension=php_mysql.dll


Kengaun [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 Hi,

 I am testing to use php5.0.0b3 and connect to MySQL 4.1.1 encountered
 connection problem:-

 ?php
 $link = mysqli_connect(localhost, purct, prcyct,purct)
 or die(Could not connect:  . mysql_error());
 echo Connected successfully;
 mysql_close($link);
 ?


 Error message:
 ---
 [04-Feb-2004 14:45:07] PHP Fatal error:  Call to undefined function
 mysql_connect() in D:\Purct\New1x.php on line 1

 Please help to advise what went wrong ?

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