note 81028 added to function.mysql-connect

From: Date: Mon, 11 Feb 2008 19:24:38 +0000
Subject: note 81028 added to function.mysql-connect
Groups: php.notes 
Request: Send a blank email to php-notes+get-136048@lists.php.net to get a copy of this message
Looks like I learned this the hard way: <? //establish connection to master db server mysql_connect (DB_HOST, DB_USER, DB_PASSWORD); mysql_select_db (DB_NAME); //establish connection to read-only slave cluster $objMySQL_Read = mysql_connect (SLAVE_DB_HOST, SLAVE_DB_USER, SLAVE_DB_PASSWORD); mysql_select_db (DB_NAME, $objMySQL_Read); $strSQL = "SELECT col1,col2 FROM " . DB_NAME . "." . "tbl1 WHERE 1=1"; $objRS = mysql_query ($strSQL, $objMySQL_Read); //returns data from slaves $strSQL = "INSERT INTO " . DB_NAME . "." . "tbl1 (col1,col2) VALUES (val1,val2)"; mysql_query ($strSQL); //expected behavior, to insert the last statement into the master db, since it doesn't reference the read-only resource explicitly. instead, it inserts the record into the last connection, even though it shouldn't, since the last connection is not a global/anonymous connection like the first one, it's $objMySQL_Read. //you'll get out of sync db's across your cluster unless you explicitly define all connection resources ?> ---- Server IP: 208.69.120.35 Probable Submitter: 69.181.152.127 ---- Manual Page -- http://www.php.net/manual/en/function.mysql-connect.php Edit -- https://master.php.net/note/edit/81028 Del: integrated -- https://master.php.net/note/delete/81028/integrated Del: useless -- https://master.php.net/note/delete/81028/useless Del: bad code -- https://master.php.net/note/delete/81028/bad+code Del: spam -- https://master.php.net/note/delete/81028/spam Del: non-english -- https://master.php.net/note/delete/81028/non-english Del: in docs -- https://master.php.net/note/delete/81028/in+docs Del: other reasons-- https://master.php.net/note/delete/81028 Reject -- https://master.php.net/note/reject/81028 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#136048) next »