How can I test MySQL?


You can use the following code to test your MySQL database:

You will need to fill in the variables for the following:

  • $database
  • $host
  • $username
  • $password
PHP Sample Code



<?php
$database = "";
$host = "";
$username = "";
$password = "";

$link = mysql_connect($host,$username,$password) 
  or die("Unable to connect: " . mysql_error());
  print "MySQL database connection successful. \n";
  
mysql_select_db("$database") or die("Could not select database");

$create = mysql_query("CREATE TABLE mysqltest (name VARCHAR(20))") 
  or die("Test table creation failed: " . mysql_error());
$insert = mysql_query("INSERT INTO mysqltest VALUES (\"It worked\")") 
  or die("Test insert failed: " . mysql_error());
$result = mysql_query("SELECT * FROM mysqltest") 
  or die("Query failed: " . mysql_error());
$drop = mysql_query("DROP TABLE mysqltest") 
  or die("Drop failed: " . mysql_error());
  
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) { 
  foreach ($line as $col_value) { 
    print "Row found: $col_value\n"; } }
	
mysql_free_result($result);
mysql_close($link);
?>







Was this content helpful?




© 2014 Rackspace US, Inc.

Except where otherwise noted, content on this site is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License


See license specifics and DISCLAIMER