First problem : there are not return in the function as it said
Second problem : php make a real connection with a unique id to a server
database
$server1 = array("localhost","user","pass")
$server2 = array("localhost2","user2","pass2")
Function mysqlConnectServer($server)
{
$uid = mysql_connect($server) or die(mysql_error());
return $uid;
}
$uidServer1 = mysqlConnectServer( $server1);
$uidServer2 = mysqlConnectServer( $server2);
$db1_1 = mysql_select_db("tava", $uidServer1);
$db1_2 = mysql_select_db("tava2", $uidServer1);
$db2_1 = mysql_select_db("tava", $uidServer2);
$db2_2 = mysql_select_db("tava2", $uidServer2);
In this exemple we used, only 2 mysql connections to create 4 databases
connections, on 2 mysql servers.
Depending of your application, you must manage server and database
connection, to manage error and problem connection, but also for performance
and don't create a server connection each time you connect to a different
database on the same mysql server.
Also look at PDO:mysql and mysqli on php.net
Mysqli is simple to use, for exemple mysqli_connect(), use a mysql_connect
or a mysql_pconnect depending of your configuration. Also mysqli check all
server connection, if already exist it dont create a new connection to the
server, but use an allready connection even your code isn't really
optimised.
PDO is more complex and, in my mind, have some problem of performance at
this time.
""Aviation Coding"" <aviationcoder@xxxxxxxxxxxxxx> a écrit dans le message
de news:3c6e2d9f0807040215w50cf1d05k785e9644515b2a6b@xxxxxxxxxxxxxxxxx
Hi all,
I am having problems with a connection to a mysql database.
I am using
----
function con()
{
mysql_connect("localhost","user","pass") or die(mysql_error());
mysql_select_db("tava") or die(mysql_error());
}
----
Now, when I call the _function_ (!)
----
con() or die("no con");
----
I get the "no con" output.
When I call the mysql_connect and mysql_select directly before executing a
query, I get some DB output. But that won't work when I am using the
function...
Any ideas would be greatly appreciated.
Cheers!
Chris
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php