Re: [PHP] Alter Table newbie help needed ...

2008-04-21 Thread revDAVE
Jason  David,

Thanks so much for your help

BTW: to reiterate the problem: I guess it was not knowing to use the 'try1'
connection ( try1.ztest) - and used 'connect2' connection instead...

Error said : Table 'connect2.ztest' doesn't exist
(connect2 was some other one I set up for something else)

Q: Is there a way to insure that it uses the right connection ( try1 - not
connect2 )?


--



On 4/20/2008 1:41 PM, Jason Norwood-Young [EMAIL PROTECTED]
wrote:

 revDave - can we see a bit more of the code in one block and not broken
 up? Makes it a bit easier to see what you're doing.

Will do - check below...



On 4/20/2008 11:08 AM, David Giragosian [EMAIL PROTECTED] wrote:

 Is try1 the name of a database? The SQL syntax is
 databasename.tablename.fieldname.
Hmmm - looking below, maybe this is the DB name?

$database_try1

As you see below - I tried this, but it gave me errors

$result = mysql_query($sql,***$database_try1*** )

This also failed...

$sql = 'ALTER TABLE `test.ztest` ADD `new4` VARCHAR(50) NOT NULL;';
$result = mysql_query($sql)

  
 When you issue a query using mysql_query() you can explicitly indicate the
 connection (returned by mysql_connect()) to use as the second parameter, e.g.,
 mysql_query($sql_Statement, $returnedConnectionObject);
  
 HTH,
  
 David



Here's the orig post with some mods:


Connection called 'try1'...

?php
# FileName=Connection_php_mysql.htm
# Type=MYSQL
# HTTP=true
$hostname_try1 = 127.0.0.1:8889;
$database_try1 = test;
$username_try1 = test;
$password_try1 = test;
$try1 = mysql_pconnect($hostname_try1, $username_try1, $password_try1) or
trigger_error(mysql_error(),E_USER_ERROR);
?



=


?php

$sql = 'ALTER TABLE `ztest` ADD `newfield3` VARCHAR(50) NOT NULL;';

$result = mysql_query($sql) or die(no good dB $sql . mysql_error());

?

maybe it needs something like:?

$result = mysql_query($sql,***$database_try1*** ) - hmmm?

I get errors like this: Warning: mysql_query(): supplied argument is not a
valid MySQL-Link resource

--
Thanks - RevDave
Cool @ hosting4days . com
[db-lists]




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



Re: [PHP] Alter Table newbie help needed ...

2008-04-21 Thread revDAVE
On 4/21/2008 2:04 PM, revDAVE [EMAIL PROTECTED] wrote:

 : Is there a way to insure that it uses the right connection ( try1 - not
 connect2 )?



- seems to be ok now with this new db selector line...

mysql_select_db($database_try1, $try1); // this new line


New ...
?php

$sql = 'ALTER TABLE `ztest` ADD `newfield3` VARCHAR(50) NOT NULL;';
mysql_select_db($database_try1, $try1);
$result = mysql_query($sql) or die(no good dB $sql . mysql_error());

?


Old - no

?php

$sql = 'ALTER TABLE `ztest` ADD `newfield3` VARCHAR(50) NOT NULL;';

$result = mysql_query($sql) or die(no good dB $sql . mysql_error());

?

--
Thanks - RevDave
Cool @ hosting4days . com
[db-lists]




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



[Fwd: Re: [PHP] Alter Table newbie help needed ...]

2008-04-21 Thread Jason Norwood-Young
Darn forgot to hit reply to all

 Forwarded Message 
From: Jason Norwood-Young [EMAIL PROTECTED]
To: revDAVE [EMAIL PROTECTED]
Subject: Re: [PHP] Alter Table newbie help needed ...
Date: Mon, 21 Apr 2008 23:52:30 +0200

On Mon, 2008-04-21 at 14:04 -0700, revDAVE wrote:
 Jason  David,
 
 Thanks so much for your help
 
 BTW: to reiterate the problem: I guess it was not knowing to use the 'try1'
 connection ( try1.ztest) - and used 'connect2' connection instead...
 
 Error said : Table 'connect2.ztest' doesn't exist
 (connect2 was some other one I set up for something else)
 
 Q: Is there a way to insure that it uses the right connection ( try1 - not
 connect2 )?

Hi revDAVE

You'll simplify your life dramatically by using one database and one
connection per application. If you're not going to do that, you can make
sure the table is there in PHP with something like:

function check_table_exists($tablename) {
$sqlresult=mysql_query(SHOW TABLES LIKE $tablename);
if (mysql_num_rows($sqlresult)==1) {
return true;
}
return false;
}

J


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



Re: [PHP] Alter Table newbie help needed ...

2008-04-20 Thread revDAVE
On 4/19/2008 2:37 PM, Jason Norwood-Young [EMAIL PROTECTED]
wrote:

 Might be obvious but you are doing mysql_query($sql);, right?

Hello Jason,

Thanks - Your idea worked well -  for a while - but then I ran into
trouble...

 I added : mysql_error() and it said:


Table 'connect2.ztest' doesn't exist

- so I guess it was not knowing to use the 'try1' connection ( try1.ztest) -
(connect2 was some other one I set up for something else)

I'm using Dreamweaver cs3 - maybe it's confused?

Q: Is there a way to insure that it uses the right connection ( try1 - not
connect2 )?


BTW: I tried `try1.ztest` but it didn't like that:

$sql = 'ALTER TABLE `try1.ztest` ADD `myfield2` VARCHAR(10) NOT NULL;';


--
Thanks - RevDave
Cool @ hosting4days . com
[db-lists]




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



Re: [PHP] Alter Table newbie help needed ...

2008-04-20 Thread David Giragosian
On 4/20/08, revDAVE [EMAIL PROTECTED] wrote:

 On 4/19/2008 2:37 PM, Jason Norwood-Young [EMAIL PROTECTED]
 wrote:

  Might be obvious but you are doing mysql_query($sql);, right?

 Hello Jason,

 Thanks - Your idea worked well -  for a while - but then I ran into
 trouble...

 I added : mysql_error() and it said:


 Table 'connect2.ztest' doesn't exist

 - so I guess it was not knowing to use the 'try1' connection ( try1.ztest)
 -
 (connect2 was some other one I set up for something else)

 I'm using Dreamweaver cs3 - maybe it's confused?

 Q: Is there a way to insure that it uses the right connection ( try1 - not
 connect2 )?


 BTW: I tried `try1.ztest` but it didn't like that:

 $sql = 'ALTER TABLE `try1.ztest` ADD `myfield2` VARCHAR(10) NOT NULL;';


Is try1 the name of a database? The SQL syntax is
databasename.tablename.fieldname.

When you issue a query using mysql_query() you can explicitly indicate the
connection (returned by mysql_connect()) to use as the second parameter,
e.g., mysql_query($sql_Statement, $returnedConnectionObject);

HTH,

David


[PHP] Alter Table newbie help needed ...

2008-04-19 Thread revDAVE
Newbie - MAC - MAMP on port 8889

I have this connection to Mysql database called 'test'


Other Php stuff works ok but now I'm trying to alter the table (never did
that before...)



Connection called 'try1'...

?php
# FileName=Connection_php_mysql.htm
# Type=MYSQL
# HTTP=true
$hostname_try1 = 127.0.0.1:8889;
$database_try1 = test;
$username_try1 = test;
$password_try1 = test;
$try1 = mysql_pconnect($hostname_try1, $username_try1, $password_try1) or
trigger_error(mysql_error(),E_USER_ERROR);
?

The lines below don't error  but also don't do anything

I must be missing something here Right? Maybe it doesn't know to use
try1 connection? How do I add that?

?php
$sql = 'ALTER TABLE `ztest` ADD `myfield2` VARCHAR(10) NOT NULL;';
---or---
$sql = 'ALTER TABLE `ztest` RENAME TO `ztest2`;';

 ?





--
Thanks - RevDave
Cool @ hosting4days . com
[db-lists]




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



Re: [PHP] Alter Table newbie help needed ...

2008-04-19 Thread Jason Norwood-Young

On Sat, 2008-04-19 at 14:23 -0700, revDAVE wrote:
 Newbie - MAC - MAMP on port 8889
 
 I have this connection to Mysql database called 'test'
 
 
 Other Php stuff works ok but now I'm trying to alter the table (never did
 that before...)
 
 
 
 Connection called 'try1'...
 
 ?php
 # FileName=Connection_php_mysql.htm
 # Type=MYSQL
 # HTTP=true
 $hostname_try1 = 127.0.0.1:8889;
 $database_try1 = test;
 $username_try1 = test;
 $password_try1 = test;
 $try1 = mysql_pconnect($hostname_try1, $username_try1, $password_try1) or
 trigger_error(mysql_error(),E_USER_ERROR);
 ?
 
 The lines below don't error  but also don't do anything
 
 I must be missing something here Right? Maybe it doesn't know to use
 try1 connection? How do I add that?
 
 ?php
 $sql = 'ALTER TABLE `ztest` ADD `myfield2` VARCHAR(10) NOT NULL;';
 ---or---
 $sql = 'ALTER TABLE `ztest` RENAME TO `ztest2`;';
 
  ?

Might be obvious but you are doing mysql_query($sql);, right?

Also add a try catch around your mysql_query to check what's happening.


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



Re: [PHP] Alter Table newbie help needed ...

2008-04-19 Thread revDAVE
On 4/19/2008 2:37 PM, Jason Norwood-Young [EMAIL PROTECTED]
wrote:

 Might be obvious but you are doing mysql_query($sql);, right?

Not so obvious to THIS newbie - now it works fine!

Thanks AGAIN!

 
 Also add a try catch around your mysql_query to check what's happening.


--
Thanks - RevDave
Cool @ hosting4days . com
[db-lists]




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