suyesh.amatya Posted July 22, 2008 Share Posted July 22, 2008 I have a php script in my machine and via it I want to access the database in the other machine with IP 192.168.0.104. The code is: mysql_connect("192.168.0.104","root",""); mysql_select_db("dbtest"); $sql="select * from dbtest"; $result=mysql_query($sql); while($data=mysql_fetch_array($result)){ echo $data['name']; } but i am not being able to do this.Need help.. Quote Link to comment Share on other sites More sharing options...
Xurion Posted July 22, 2008 Share Posted July 22, 2008 Use this code, and see if any errors appear: mysql_connect("192.168.0.104","root","") or die(mysql_error()); mysql_select_db("dbtest") or die(mysql_error()); $sql="select * from dbtest"; $result=mysql_query($sql) or die(mysql_error()); while($data=mysql_fetch_array($result)){ echo $data['name']; } Quote Link to comment Share on other sites More sharing options...
mbeals Posted July 22, 2008 Share Posted July 22, 2008 first off, PUT A PASSWORD ON YOUR ROOT ACCOUNT Secondly, log into the remote server and add a user with remote connection privileges: CREATE USER 'test'@ '192.168.3.198' ...... where the IP or hostname is the ip or hostname of the computer that will be connecting to the server. If you wish to allow any computer to connect, use %. Finish the CREATE statement with the required privileges and database restrictions. DO NOT: 1. grant root remote connections (especially with no password) 2. grant the remote user more privileges then he needs (if he doesn't need to be able to alter or drop tables, don't let him) 3. give the remote user admin rights (create users, grant permissions, lock tables, etc...) 4. give the remote user a null or weak password This query string should do what you want and be reasonably secure: CREATE USER '<user>'@'<host>' IDENTIFIED BY '<passwd>'; GRANT SELECT , INSERT , UPDATE , DELETE ON `<database>` . * TO '<user>'@'<host>'; change the stuff identified by < > tags Quote Link to comment Share on other sites More sharing options...
Xurion Posted July 22, 2008 Share Posted July 22, 2008 I assumed he/she left the password out of the code for obvious reasons. Quote Link to comment Share on other sites More sharing options...
mbeals Posted July 22, 2008 Share Posted July 22, 2008 you never know...and besides it's really not wise to use the root account as a normal user. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.