Forum Moderators: coopster
do i need two connect scripts on my pages, one for local one for remote?
if i call the db loaclly the same name and username etc. as the remote mysql db, would that work?
if so, how do i do that? the db locally will mirror the remote db ( not sure how to do that yet! )
i am downloading mysql for osx at the moment, just wanted to check before i go too far!
hope that makes some sense, hope you can help me out, like i said this is all very new to me.
If you are asking, can I setup my test server just like the production server and run the same exact scripts without having to modify the mysql_connection information, the answer is Yes, if the server parameter in your mysql_connect [us4.php.net] function for your connection is localhost. Whenever you specify "localhost" or "localhost:port" as server, the MySQL client library will override this and try to connect to a local socket (named pipe on Windows). If you want to use TCP/IP, use "127.0.0.1" instead of "localhost".
I generally create a database connection script that I include when necessary. This way, when developing for different servers, I can simply copy and modify my connection(s) in one script:
database_connection.inc.php
<?php
$db_server = 'localhost';
$db_user = 'userid';
$db_pwd = 'password';
$db_name = 'databasename';
$db_link = @mysql_connect($db_server, $db_user, $db_pwd)
or exit('Could not connect: ' . mysql_error());
$db = @mysql_select_db($db_name, $db_link)
or exit('Could not select database: ' . mysql_error());
?>
some_script.php
<?php
include_once("database_connection.inc.php");
// more code here...
?>
Somebody may offer a better solution, but you may want to have a look at mysqldump [mysql.com].
so i should not need to change any of my connection scripts, thats great. so when it is running locally it automatically finds the local db and connects with that?
its for my own site, so i only have one connect script i use at the moment.
what about the user-name and password? when the pages are running locally does it ignore them and connect to the local db anyway? or should i set up my local db with the same user-name and password as my remote one?
sorry, if im asking stupid questions? its quite a lot to get your head around. im a designer primarily but want to get my own site running via a db, rather than having to hand code each page. (eatpixels.com) it seems to working fine at the moment. i have tried to look around on the net to find answers before posting, its hard to know what to look!
downloading mysql for osx at the moment ,i only have a 56k connection so its taking for ever. i will let you know how i get on.
many thanks