theog writes "I have been using mysql with PHP for quite a while now and have encountered questions by friends and colleagues regarding how to connect and exactly what needs to be done, the following is a simple example which may put you on track reagrding connecting to a mysql server using PHP.
Well first what I ask myself before deciding to use mysql or any sql for that matter is what am I going to use it for, the answer to this question is the most important question as it will decide how your database scheme will look like, and in some cases even lead you to a track where no sql is needed to accomplish the task you set.
another thing to remember is that PHP must be compiled with mysql support, ( --with-mysql ) and in some case even the libmysqlclient must be installed in order to allow PHP to use mysql properly.
The following is what I use to connect to a mysql server:
mysql_connect("", "", "") or die(mysql_error());
mysql_select_db() or die(mysql_error());
$result = mysql_query("") or die(mysql_error());
$row = mysql_fetch_array( $result );
print $row[''];
In the above lines:
- The host name or ip address of the mysql server.
- The user name to connect to the database with.
- The password for the user above.
- The database to use.
- The sql query itself (i.e. select, insert, update etc...).
- the coulmn to present as a result.
Should you have any further questions, I will be more then happy to reply to them just post a comment with your question.
"