Fix horribly broken implementation of the PDO mysql_ abstraction - this REALLY needs to be done properly.

develop
Sven Slootweg 12 years ago
parent 224769ebb4
commit c59aad3be6

@ -495,7 +495,7 @@ abstract class CPHPDatabaseRecordClass extends CPHPBaseClass
$query = "UPDATE {$this->table_name} SET {$sQueryKeysValues} WHERE `{$this->id_field}` = '{$this->sId}'"; $query = "UPDATE {$this->table_name} SET {$sQueryKeysValues} WHERE `{$this->id_field}` = '{$this->sId}'";
} }
if($result = mysql_query_cached($query, 0)) if($result = mysql_query_cached($query, 0, "", true))
{ {
if($insert_mode == CPHP_INSERTMODE_INSERT) if($insert_mode == CPHP_INSERTMODE_INSERT)
{ {

@ -90,7 +90,7 @@ function mc_delete($key)
} }
} }
function mysql_query_cached($query, $expiry = 60, $key = "") function mysql_query_cached($query, $expiry = 60, $key = "", $exec = false)
{ {
global $cphp_config, $database; global $cphp_config, $database;
@ -138,7 +138,7 @@ function mysql_query_cached($query, $expiry = 60, $key = "")
else else
{ {
/* Transparently use PDO to run the query. */ /* Transparently use PDO to run the query. */
if($statement = $database->Query($query)) if($exec === false && $statement = $database->query($query))
{ {
if($data = $statement->fetchAll(PDO::FETCH_ASSOC)) if($data = $statement->fetchAll(PDO::FETCH_ASSOC))
{ {
@ -151,6 +151,8 @@ function mysql_query_cached($query, $expiry = 60, $key = "")
$return_object->source = "database"; $return_object->source = "database";
$return_object->data = $result; $return_object->data = $result;
return $return_object;
} }
else else
{ {
@ -162,6 +164,25 @@ function mysql_query_cached($query, $expiry = 60, $key = "")
return null; return null;
} }
} }
elseif($exec === true)
{
$statement = $database->exec($query);
if(is_null($statement))
{
return null;
}
elseif($statement == 0)
{
return false;
}
else
{
$return_object->source = "database";
$return_object->data = $result;
return $return_object;
}
}
else else
{ {
return null; return null;

Loading…
Cancel
Save