Currently for our login system etc we use a connect.php file with the following contents
$connect_error = 'Sorry, we\'re currently experiencing connection problems.';
mysql_connect('localhost', 'x', 'x') or die($connect_error);
mysql_select_db('x');
We are currently developing a system that we would like users to be able to add devices to their account
The main table we have stores all the users info e.g. First Name, Last Name, Email, Password
To this table we are adding the following fields – Device 1, Device 2, Device 3
Along side this we would also like to have access to another database, we want to hold the device id’s in the main database so we know who owns what devices.
The second database will consist of Device ID, Lat, Long, Time
We would like to be able to read out of either database, I’m not sure how we would specify the database to connect to as I’ve only ever dealt with the one database
I’m not sure if its doable or if i’m going about it the totally wrong way – Both databases will be on the same server and we can assign the same user to both databases if that helps
Thanks
First of all, You should not use
mysql_*functions as the are deprecated. Use MySQLi or PDO for this.In Mysql the solution is to use the link identifier returned by mysql_connect. But if you use MySQLi or PDO you need to create those object first and use that object. OOP interface of MySQLi has NO concept of link identifier. Read this page from PHP manual that helps you to migrate. For PDO use this tutorial to learn.
For MySQLi extension, its already a object and the object contains database information.
For MySQL extension, mysql_connect() returns a links identifier. You should save it in a variable and use it.