This is a very simple PHP class to check MySQL connection.Please read my other blog to create the MySQL table to make things work.
define("server","localhost"); define("conn_username", "root"); define("conn_password", "root"); define("database_name", "database_1.1");
require "database.inc.php"; class mysql { function connect() { @mysql_connect(server,conn_username,conn_password); @mysql_select_db(database_name); } function query($query) { $result = mysql_query($query); if (!$result) { echo 'Could not run query: ' . mysql_error(); exit; } else{ return $result; } } function showresult($result) { $arr = array(); @mysql_data_seek($result); while ($row = mysql_fetch_array($result, MYSQL_BOTH)) { array_push($arr, $row); } return $arr; } function end() { @mysql_close(); } } $mysql = new mysql(); $mysql->connect(); // $query = $mysql->query("SELECT * FROM Employee"); print_r($mysql->showresult(/*$query)*/$mysql->query("SELECT * FROM Employee"))); $mysql->end();
Post a Comment