PHP Script to Send Test Results from Lectora to a MySql Database
March 13, 2008 12:00 AM
I had written some php for a past job that involved reading from and writing to a MySQL database. Here is some of the stripped code of how to connect to and write to a database. I can't test any of it anymore, but hopefully it will at least be helpful to you.// Connecting, selecting database $link = mysql_connect('localhost', 'mysql_user', 'mysql_password') - Change mysql_user to SQL Username, and mysql_password to Password or die('Could not connect: ' . mysql_error()); mysql_select_db('mysql_databas e') - Change mysql_database is the SQL Database you are accessing or die('Could not select database');//Preparing to write data to MySQL database $sql = "INSERT INTO 'mysql_table' (`column_one_name`, `column_two_name`, `column_three_name`) VALUES ('$variable_one', '$variable_two', '$variable_three')"; - Change mysql_table is the name of the Table you are accessing - Change column_name_one to your identifying name, etc. - Change $varaible_one to your variable, etc.//Writing to database $result = mysql_query($sql); or die('Insert failed: ' . mysql_error());// Free resultset mysql_free_result($result);Your best bet is to start out just writing a simple php file that only does these things and make sure it works. You can do this in notepad, or anything else as long as you save it as php. Make up some variables and see if you can write them to the database. These must be run from your server. I haven't worked with php for about a year, but let me know if I can help any more.
Discussions have been disabled for this post