| 1 |
<?php
|
| 2 |
/**
|
| 3 |
* Basic wrappers for MySQL
|
| 4 |
*
|
| 5 |
*
|
| 6 |
*
|
| 7 |
*
|
| 8 |
* @copyright AGPL
|
| 9 |
* @author Jonathan Hendler
|
| 10 |
* @date 3/25/2006
|
| 11 |
*
|
| 12 |
*
|
| 13 |
* @package SONIA
|
| 14 |
* @version Alpha 0.01
|
| 15 |
*
|
| 16 |
* */
|
| 17 |
|
| 18 |
|
| 19 |
class SONIA_TEST_MYSQL_DB
|
| 20 |
{
|
| 21 |
var $tdb_conn;
|
| 22 |
|
| 23 |
/**
|
| 24 |
* Constructor initiates a non-persistant DB connection
|
| 25 |
* */
|
| 26 |
function SONIA_TEST_MYSQL_DB($db_name,$db_pass='',$db_user='root',$db_host='localhost')
|
| 27 |
{
|
| 28 |
|
| 29 |
global $tdb_conn;
|
| 30 |
|
| 31 |
$tdb_conn = mysql_pconnect($db_host, $db_user, $db_pass);
|
| 32 |
|
| 33 |
if(isset($tdb_conn))
|
| 34 |
{
|
| 35 |
if(!mysql_select_db($db_name))
|
| 36 |
{
|
| 37 |
echo mysql_real_escape_string(mysql_error());
|
| 38 |
}
|
| 39 |
}
|
| 40 |
else
|
| 41 |
{
|
| 42 |
echo mysql_real_escape_string(mysql_error());
|
| 43 |
}
|
| 44 |
} // end BeyondKeywordDB()
|
| 45 |
|
| 46 |
|
| 47 |
/**
|
| 48 |
*
|
| 49 |
* imple wrapper for getting an ID on insert
|
| 50 |
* */
|
| 51 |
function singleInsertQuery($query)
|
| 52 |
{
|
| 53 |
$this->query($query);
|
| 54 |
return mysql_insert_id();
|
| 55 |
}
|
| 56 |
|
| 57 |
/**
|
| 58 |
* simple function wrapper for sending a simple query
|
| 59 |
* */
|
| 60 |
function query($query)
|
| 61 |
{
|
| 62 |
$result = mysql_query($query);
|
| 63 |
if ($result)
|
| 64 |
{
|
| 65 |
return $result;
|
| 66 |
}
|
| 67 |
else
|
| 68 |
{
|
| 69 |
echo $query;
|
| 70 |
echo mysql_real_escape_string(mysql_error());
|
| 71 |
return null;
|
| 72 |
}
|
| 73 |
} //end query()
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
/**
|
| 79 |
* Simple function wrapper for getting multiple results in
|
| 80 |
* a convienient form
|
| 81 |
* */
|
| 82 |
function get_array($query)
|
| 83 |
{
|
| 84 |
$data = array();
|
| 85 |
|
| 86 |
if ($result = $this->query($query))
|
| 87 |
{
|
| 88 |
while($row = mysql_fetch_assoc($result))
|
| 89 |
$data[] = $row;
|
| 90 |
}
|
| 91 |
else
|
| 92 |
{
|
| 93 |
echo mysql_real_escape_string(mysql_error());
|
| 94 |
}
|
| 95 |
|
| 96 |
return($data);
|
| 97 |
|
| 98 |
} //end get_array()
|
| 99 |
}// end class
|
| 100 |
|
| 101 |
?>
|