Permalink
Browse files

Changed all mysql_ function calls to use the xf_db_ wrapper functions…

…. Added driver convention in xf/db/drivers . So far there are drivers for mysql and mysqli only. Not heavily tested yet either but seem to work on preliminary sample apps. Driver can be specified by adding driver attribute to the _database section of the conf.ini file. E.g. driver=mysql or driver=mysqli, where the driver name corresponds to the name of the PHP file in xf/db/drivers.
  • Loading branch information...
shannah committed Jun 4, 2014
1 parent 3a9316d commit 64ad7b26de8c94349d0b9d5647b43547f4d3931a
Showing with 2,409 additions and 1,183 deletions.
  1. +14 −14 DB/Sync.php
  2. +19 −14 Dataface/Application.php
  3. +18 −18 Dataface/AuthenticationTool.php
  4. +13 −13 Dataface/Clipboard.php
  5. +4 −4 Dataface/ConfigTool.php
  6. +2 −2 Dataface/ConfigTool/createConfigTable.function.php
  7. +8 −8 Dataface/ConfigTool/setConfigParam.function.php
  8. +8 −8 Dataface/ConfigWriter.php
  9. +1 −1 Dataface/CopyTool.php
  10. +14 −14 Dataface/DB.php
  11. +4 −4 Dataface/DelegateClass.php
  12. +11 −11 Dataface/DeleteForm.php
  13. +48 −48 Dataface/HistoryTool.php
  14. +32 −32 Dataface/IO.php
  15. +17 −17 Dataface/Index.php
  16. +4 −4 Dataface/LanguageTool.php
  17. +16 −16 Dataface/MetadataTool.php
  18. +13 −13 Dataface/ModuleTool.php
  19. +21 −21 Dataface/OutputCache.php
  20. +2 −2 Dataface/PageCache.php
  21. +11 −11 Dataface/PreferencesTool.php
  22. +2 −2 Dataface/PreferencesTool/_createPreferencesTable.php
  23. +14 −14 Dataface/QueryTool.php
  24. +11 −11 Dataface/Record.php
  25. +2 −2 Dataface/RecordGrid.php
  26. +1 −1 Dataface/ReferenceBrowser.php
  27. +1 −1 Dataface/Relationship.php
  28. +7 −7 Dataface/ResultController.php
  29. +3 −3 Dataface/ResultList.php
  30. +4 −4 Dataface/ResultReader.php
  31. +63 −63 Dataface/Table.php
  32. +9 −9 Dataface/Table/builder.php
  33. +40 −40 Dataface/TranslationTool.php
  34. +4 −4 Dataface/ValuelistTool.php
  35. +11 −11 actions/activate.php
  36. +1 −1 actions/ajax_form.php
  37. +4 −4 actions/clear_views.php
  38. +1 −1 actions/edit.php
  39. +16 −16 actions/forgot_password.php
  40. +5 −5 actions/get_page_to_translate.php
  41. +9 −9 actions/install.php
  42. +4 −4 actions/manage_output_cache.php
  43. +1 −1 actions/new.php
  44. +9 −9 actions/register.php
  45. +1 −1 actions/translate.php
  46. +2 −2 blob.php
  47. +15 −15 installer.php
  48. +1 −1 lib/DB/common.php
  49. +30 −30 lib/DB/mysql.php
  50. +1,118 −0 lib/PEAR.php
  51. +11 −11 lib/feedcreator.class.php
  52. +25 −25 lib/mysql_functions.php
  53. +1 −1 lib/phpThumb/demo/phpThumb.demo.object.php
  54. +14 −14 lib/phpThumb/phpThumb.php
  55. +1 −1 lib/phpThumb/phpthumb.class.php
  56. +7 −7 modules/XataJax/classes/xatacard/layout/MySQLDataSource.php
  57. +17 −17 public-api.php
  58. +340 −340 tests/BaseTest.php
  59. +2 −2 tests/BaseTest2.php
  60. +8 −8 tests/DB_Sync_Test.php
  61. +12 −12 tests/DB_Test.php
  62. +11 −11 tests/HistoryToolTest.php
  63. +24 −24 tests/IOTest.php
  64. +16 −16 tests/MetadataToolTest.php
  65. +2 −2 tests/QueryBuilderTest.php
  66. +63 −63 tests/QueryTranslator_Test.php
  67. +4 −4 tests/Table_builderTest.php
  68. +15 −15 tests/TranslationToolTest.php
  69. +8 −8 tests/TreeTableTest.php
  70. +2 −2 tests/ValuelistToolTest.php
  71. +8 −8 tests/tables/formulas/formulas.php
  72. +6 −6 tests/test_Dataface_Record.php
  73. +2 −2 tests/testconfig.php
  74. +20 −20 xf/db/Database.php
  75. +67 −7 xf/db/drivers/mysql.php
  76. +54 −11 xf/db/drivers/mysqli.php
View
@@ -83,27 +83,27 @@ function loadTableData(){
$this->checkTableNames();
$res = mysql_query("show full fields from `".$this->table1."`", $this->db1);
if ( !$res ) trigger_error(mysql_error($this->db1));
$res = xf_db_query("show full fields from `".$this->table1."`", $this->db1);
if ( !$res ) trigger_error(xf_db_error($this->db1));
$this->table1Data = array();
while ( $row = mysql_fetch_assoc($res) ){
while ( $row = xf_db_fetch_assoc($res) ){
$this->table1Data[$row['Field']] = $row;
}
@mysql_free_result($res);
@xf_db_free_result($res);
$res = mysql_query("show columns from `".$this->table2."`", $this->db2);
if ( !$res ) trigger_error(mysql_error($this->db2));
$res = xf_db_query("show columns from `".$this->table2."`", $this->db2);
if ( !$res ) trigger_error(xf_db_error($this->db2));
$this->table2Data = array();
while ( $row = mysql_fetch_assoc($res) ){
while ( $row = xf_db_fetch_assoc($res) ){
$this->table2Data[$row['Field']] = $row;
}
@mysql_free_result($res);
@xf_db_free_result($res);
}
@@ -181,8 +181,8 @@ function syncField($fieldname, $after=null, $renameMap=null){
}
$sql = "alter table `{$this->table2}` change `{$fieldname}` ".$this->fieldArrayToSQLDef($this->table1Data[$newname]);
$res = mysql_query($sql, $this->db2);
if ( !$res ) trigger_error(mysql_error($this->db2), E_USER_ERROR);
$res = xf_db_query($sql, $this->db2);
if ( !$res ) trigger_error(xf_db_error($this->db2), E_USER_ERROR);
} else {
@@ -196,14 +196,14 @@ function syncField($fieldname, $after=null, $renameMap=null){
if ( isset($after) ){
$sql .= "after `{$after}`";
}
$res = mysql_query($sql, $this->db2);
if ( !$res ) trigger_error($sql."\n".mysql_error($this->db2), E_USER_ERROR);
$res = xf_db_query($sql, $this->db2);
if ( !$res ) trigger_error($sql."\n".xf_db_error($this->db2), E_USER_ERROR);
} else if ( $this->table1Data[$fieldname] != $this->table2Data[$fieldname] ) {
$sql = "alter table `{$this->table2}` change `{$fieldname}` ".$this->fieldArrayToSQLDef($this->table1Data[$fieldname]);
$res = mysql_query($sql, $this->db2);
if ( !$res ) trigger_error(mysql_error($this->db2), E_USER_ERROR);
$res = xf_db_query($sql, $this->db2);
if ( !$res ) trigger_error(xf_db_error($this->db2), E_USER_ERROR);
} else {
View
@@ -576,17 +576,22 @@ function Dataface_Application($conf = null){
</pre>', E_USER_ERROR);
}
if ( @$dbinfo['persistent'] ){
$this->_db = mysql_pconnect( $dbinfo['host'], $dbinfo['user'], $dbinfo['password'] );
} else {
$this->_db = mysql_connect( $dbinfo['host'], $dbinfo['user'], $dbinfo['password'] );
if ( !isset($dbinfo['driver']) ){
$dbinfo['driver'] = 'mysql';
}
require_once 'xf/db/drivers/'.basename($dbinfo['driver']).'.php';
//if ( @$dbinfo['persistent'] ){
// $this->_db = xf_db_pconnect( $dbinfo['host'], $dbinfo['user'], $dbinfo['password'] );
//} else {
$this->_db = xf_db_connect( $dbinfo['host'], $dbinfo['user'], $dbinfo['password'] );
//}
if ( !$this->_db ){
throw new Exception('Error connecting to the database: '.mysql_error());
throw new Exception('Error connecting to the database: '.xf_db_error());
}
$this->mysqlVersion = mysql_get_server_info($this->_db);
mysql_select_db( $dbinfo['name'] ) or die("Could not select DB: ".mysql_error($this->_db));
$this->mysqlVersion = xf_db_get_server_info($this->_db);
xf_db_select_db( $dbinfo['name'], $this->_db) or die("Could not select DB: ".xf_db_error($this->_db));
}
//if ( !defined( 'DATAFACE_DB_HANDLE') ) define('DATAFACE_DB_HANDLE', $this->_db);
@@ -665,8 +670,8 @@ function Dataface_Application($conf = null){
if ( @$this->_conf['support_transactions'] ){
// We will support transactions
@mysql_query('SET AUTOCOMMIT=0', $this->_db);
@mysql_query('START TRANSACTION', $this->_db);
@xf_db_query('SET AUTOCOMMIT=0', $this->_db);
@xf_db_query('START TRANSACTION', $this->_db);
}
if ( !isset($this->_conf['default_ie']) ) $this->_conf['default_ie'] = 'UTF-8';
@@ -703,11 +708,11 @@ function Dataface_Application($conf = null){
define('XF_OUTPUT_ENCODING', $this->_conf['oe']);
if ( $this->_conf['oe'] == 'UTF-8' ){
$res = mysql_query('set character_set_results = \'utf8\'', $this->_db);
mysql_query("SET NAMES utf8", $this->_db);
$res = xf_db_query('set character_set_results = \'utf8\'', $this->_db);
xf_db_query("SET NAMES utf8", $this->_db);
}
if ( $this->_conf['ie'] == 'UTF-8' ){
$res = mysql_query('set character_set_client = \'utf8\'', $this->_db);
$res = xf_db_query('set character_set_client = \'utf8\'', $this->_db);
}
@@ -1108,7 +1113,7 @@ function &conf(){
*/
function getMySQLMajorVersion(){
if ( !isset($this->mysqlVersion) ){
$this->mysqlVersion = mysql_get_server_info($this->_db);
$this->mysqlVersion = xf_db_get_server_info($this->_db);
}
list($mv) = explode('.',$this->mysqlVersion);
return intval($mv);
@@ -3184,7 +3189,7 @@ function _cleanup(){
$this->writeSessionData();
}
if ( @$this->_conf['support_transactions'] ){
@mysql_query('COMMIT', $this->_db);
@xf_db_query('COMMIT', $this->_db);
}
}
@@ -135,7 +135,7 @@ function checkCredentials(){
}
import('Dataface/Serializer.php');
$serializer = new Dataface_Serializer($this->usersTable);
//$res = mysql_query(
//$res = xf_db_query(
$sql = "SELECT `".$this->usernameColumn."` FROM `".$this->usersTable."`
WHERE `".$this->usernameColumn."`='".addslashes(
$serializer->serialize($this->usernameColumn, $creds['UserName'])
@@ -145,20 +145,20 @@ function checkCredentials(){
$this->passwordColumn,
"'".addslashes($serializer->serialize($this->passwordColumn, $creds['Password']))."'"
);
$res = mysql_query($sql, $app->db());
if ( !$res ) throw new Exception(mysql_error($app->db()), E_USER_ERROR);
$res = xf_db_query($sql, $app->db());
if ( !$res ) throw new Exception(xf_db_error($app->db()), E_USER_ERROR);
if ( mysql_num_rows($res) === 0 ){
if ( xf_db_num_rows($res) === 0 ){
return false;
}
$found = false;
while ( $row = mysql_fetch_row($res) ){
while ( $row = xf_db_fetch_row($res) ){
if ( strcmp($row[0], $creds['UserName'])===0 ){
$found=true;
break;
}
}
@mysql_free_result($res);
@xf_db_free_result($res);
return $found;
}
@@ -422,13 +422,13 @@ function getLoggedInUsername(){
}
function _createFailedLoginsTable(){
$res = mysql_query("create table if not exists `dataface__failed_logins` (
$res = xf_db_query("create table if not exists `dataface__failed_logins` (
`attempt_id` int(11) not null auto_increment primary key,
`ip_address` varchar(32) not null,
`username` varchar(32) not null,
`time_of_attempt` int(11) not null
) ENGINE=InnoDB DEFAULT CHARSET=utf8", df_db());
if ( !$res ) throw new Exception(mysql_error(df_db()), E_USER_ERROR);
if ( !$res ) throw new Exception(xf_db_error(df_db()), E_USER_ERROR);
}
function flagFailedAttempt($credentials){
@@ -439,30 +439,30 @@ function flagFailedAttempt($credentials){
$del->$method($credentials['UserName'], $_SERVER['REMOTE_ADDR'], time() );
}
$this->_createFailedLoginsTable();
$res = mysql_query("insert into `dataface__failed_logins` (ip_address,username,time_of_attempt) values (
$res = xf_db_query("insert into `dataface__failed_logins` (ip_address,username,time_of_attempt) values (
'".addslashes($_SERVER['REMOTE_ADDR'])."',
'".addslashes($credentials['UserName'])."',
'".addslashes(time())."'
)", df_db());
if ( !$res ) throw new Exception(mysql_error(df_db()), E_USER_ERROR);
if ( !$res ) throw new Exception(xf_db_error(df_db()), E_USER_ERROR);
}
function clearFailedAttempts(){
$this->_createFailedLoginsTable();
$res = mysql_query("delete from `dataface__failed_logins` where ip_address='".addslashes($_SERVER['REMOTE_ADDR'])."'", df_db());
if ( !$res ) throw new Exception(mysql_error(df_db()));
$res = xf_db_query("delete from `dataface__failed_logins` where ip_address='".addslashes($_SERVER['REMOTE_ADDR'])."'", df_db());
if ( !$res ) throw new Exception(xf_db_error(df_db()));
}
function isLockedOut(){
$this->_createFailedLoginsTable();
$res = mysql_query("delete from `dataface__failed_logins` where `time_of_attempt` < ".(time()-(60*30)), df_db());
if ( !$res ) throw new Exception(mysql_error(df_db()), E_USER_ERROR);
$res = mysql_query("select count(*) from `dataface__failed_logins` where `ip_address`='".addslashes($_SERVER['REMOTE_ADDR'])."'", df_db());
if ( !$res ) throw new Exception(mysql_error(df_db()), E_USER_ERROR);
list($num) = mysql_fetch_row($res);
@mysql_free_result($res);
$res = xf_db_query("delete from `dataface__failed_logins` where `time_of_attempt` < ".(time()-(60*30)), df_db());
if ( !$res ) throw new Exception(xf_db_error(df_db()), E_USER_ERROR);
$res = xf_db_query("select count(*) from `dataface__failed_logins` where `ip_address`='".addslashes($_SERVER['REMOTE_ADDR'])."'", df_db());
if ( !$res ) throw new Exception(xf_db_error(df_db()), E_USER_ERROR);
list($num) = xf_db_fetch_row($res);
@xf_db_free_result($res);
return ($num > 20);
}
View
@@ -30,7 +30,7 @@ function isInstalled(){
if ( $isInstalled == -1 ){
$app =& Dataface_Application::getInstance();
$isInstalled = ( mysql_num_rows(mysql_query("show tables like '".Dataface_Clipboard_tablename."'", $app->db())) == 0 );
$isInstalled = ( xf_db_num_rows(xf_db_query("show tables like '".Dataface_Clipboard_tablename."'", $app->db())) == 0 );
}
return $isInstalled;
}
@@ -43,15 +43,15 @@ function isInstalled(){
function install(){
if ( !Dataface_Clipboard::isInstalled() ){
$app =& Dataface_Application::getInstance();
mysql_query(
xf_db_query(
"CREATE TABLE `".Dataface_Clipboard_tablename."` (
`clipid` INT(11) auto_increment NOT NULL,
`clipperid` VARCHAR(32) NOT NULL,
`cut` TINYINT(1) DEFAULT 0,
`recordids` TEXT,
`lastmodified` datetime,
PRIMARY KEY (`clipid`),
UNIQUE (`clipperid`))", $app->db()) or trigger_error("Failed to create clipboard table: ".mysql_error($app->db()), E_USER_ERROR);
UNIQUE (`clipperid`))", $app->db()) or trigger_error("Failed to create clipboard table: ".xf_db_error($app->db()), E_USER_ERROR);
return true;
}
return false;
@@ -65,8 +65,8 @@ function install(){
*/
function clean(){
$app =& Dataface_Application::getInstance();
mysql_query("delete from `".Dataface_Clipboard_tablename."` where UNIX_TIMESTAMP(`lastmodified`) > ".(time()-Dataface_Clipboard_lifetime),
$app->db()) or trigger_error("Failed to clean old data from the clipboard: ".mysql_error($app->db()), E_USER_ERROR);
xf_db_query("delete from `".Dataface_Clipboard_tablename."` where UNIX_TIMESTAMP(`lastmodified`) > ".(time()-Dataface_Clipboard_lifetime),
$app->db()) or trigger_error("Failed to clean old data from the clipboard: ".xf_db_error($app->db()), E_USER_ERROR);
}
@@ -123,7 +123,7 @@ public static function &getInstance(){
* @return boolean True if the clipboard is empty for the current user.
*/
function empty(){
return (mysql_num_rows(mysql_query("select count(*) from `".Dataface_Clipboard_tablename."` where `clipperid`='".addslashes($this->id)."'")) == 0);
return (xf_db_num_rows(xf_db_query("select count(*) from `".Dataface_Clipboard_tablename."` where `clipperid`='".addslashes($this->id)."'")) == 0);
}
@@ -142,15 +142,15 @@ function copy($recordids){
$this->clearLogs();
$app =& Dataface_Application::getInstance();
Dataface_Clipboard::shotgunClean();
$res = mysql_query(
$res = xf_db_query(
"REPLACE INTO `".Dataface_Clipboard_tablename."`
(`clipperid`,`cut`,`recordids`,`lastmodified`)
VALUES
('".addslashes($this->id)."',
0,'".addslashes(implode("\n",$recordids))."', NOW()
)", $app->db();
if ( !$res ){
return PEAR::raiseError(mysql_error($app->db()));
return PEAR::raiseError(xf_db_error($app->db()));
}
return true;
@@ -168,15 +168,15 @@ function cut($recordids){
$this->clearLogs();
$app =& Dataface_Application::getInstance();
Dataface_Clipboard::shotgunClean();
$res = mysql_query(
$res = xf_db_query(
"REPLACE INTO `".Dataface_Clipboard_tablename."`
(`clipperid`,`cut`,`recordids`,`lastmodified`)
VALUES
('".addslashes($this->id)."',
1,'".addslashes(implode("\n",$recordids))."', NOW()
)", $app->db();
if ( !$res ){
return PEAR::raiseError(mysql_error($app->db()));
return PEAR::raiseError(xf_db_error($app->db()));
}
return true;
}
@@ -197,9 +197,9 @@ function paste($destid, $relationship=null){
$this->clearLogs();
$app =& Dataface_Application::getInstance();
Dataface_Clipboard::shotgunClean();
$res = mysql_query("SELECT * FROM `".Dataface_Clipboard_tablename."` where `clipperid`='".addslashes($this->id)."'", $app->db());
if ( mysql_num_rows($res)>0 ){
$row = mysql_fetch_assoc($res);
$res = xf_db_query("SELECT * FROM `".Dataface_Clipboard_tablename."` where `clipperid`='".addslashes($this->id)."'", $app->db());
if ( xf_db_num_rows($res)>0 ){
$row = xf_db_fetch_assoc($res);
} else {
return PEAR::raiseError('The clipboard is empty.');
}
View
@@ -459,22 +459,22 @@ function parse_ini_file($path, $sections=false){
$sql = $this->buildConfigQuery($path, $username, $app->_conf['lang']);
$res = @mysql_query($sql, $app->db());
$res = @xf_db_query($sql, $app->db());
if (!$res ){
$this->createConfigTable();
$res = mysql_query($sql, $app->db());
$res = xf_db_query($sql, $app->db());
}
if ( !$res ){
return $config;
}
while ( $row = mysql_fetch_assoc($res) ){
while ( $row = xf_db_fetch_assoc($res) ){
if ( !$row['section'] ){
$config[$row['file']][$row['key']] = $row['value'];
} else {
$config[$row['file']][$row['section']][$row['key']] = $row['value'];
}
}
@mysql_free_result($res);
@xf_db_free_result($res);
}
@@ -20,9 +20,9 @@ function Dataface_ConfigTool_createConfigTable(){
`username` varchar(32),
`priority` int(5) default 5
)";
$res = mysql_query($sql, df_db());
$res = xf_db_query($sql, df_db());
if ( !$res ){
throw new Exception(mysql_error(df_db()), E_USER_ERROR);
throw new Exception(xf_db_error(df_db()), E_USER_ERROR);
}
}
Oops, something went wrong.

0 comments on commit 64ad7b2

Please sign in to comment.