Re: database hell

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 12 Jul 2012, at 12:29, Nick Edwards wrote:

> We have a program that manages users, throughout all database calls
> 
> created as:
> $connect = mysql_connect($db_host--other variables);
> mysql_query("Delete from clients where id=$User");
> 
> All this works good, but, we need, in the delete function to delete
> from another database
> 
> $connmy=mysql_connect("host","user","pass");
>                    mysql_select_db("vsq",$connmy);
>                    mysql_query("DELETE from userprefs where clientr='$User'");
> $mysql_close($connmy);
> this fails, unless we use a mysql_close prior to it, and then
> reconnect to original database after we run this delete, how can we
> get around this without closing and reopening?
> We have a  perl script doing similar for manual runs, and it works
> well knowing that $connmy is not $connect, I'm sure there is a simple
> way to tell php but  I'm darned if I can see it.

The mysql_query method takes a second parameter specifying the MySQL connection to which to send the query. If you're dealing with multiple hosts you will want to add that to every single mysql_* function call that supports it, otherwise you could end up running queries on the wrong database.

You may also want to note that using the mysql_* functions is now discouraged in favour of MySQLi or PDO: http://php.net/mysqlinfo.api.choosing

-Stuart

-- 
Stuart Dallas
3ft9 Ltd
http://3ft9.com/

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux