•  » Engine
  •  » [Piwigo 2.5+] use of mysql_* function is forbidden

#1 2013-02-27 14:48:06

Piwigo Team
Nantes, France, Europe

[Piwigo 2.5+] use of mysql_* function is forbidden

Hi plugin developpers,

With Piwigo 2.5 mistic100 has implemented the new MySQL library mysqli in addition to mysql. By default, if available, Piwigo will load mysqli. There are 2 issues:

1) mysql_* functions are broken

With mysqli you can expect all functions mysql_* to be broken. They must be replaced by pwg_db_* equivalent:

mysql_query => pwg_query
mysql_fetch_row => pwg_db_fetch_row
mysql_fetch_assoc => pwg_db_fetch_assoc
mysql_insert_id => pwg_db_insert_id
mysql_num_rows => pwg_db_num_rows
mysql_real_escape_string => pwg_db_real_escape_string

2) mysql_fetch_array

Since pwg_db_fetch_array does not exist in Piwigo 2.4, some of you have used mysql_fetch_array instead. To get Piwigo 2.5 compatibility, you can simply change to pwg_db_fetch_array, but compatibility with Piwigo 2.4 will be broken. If you want to keep compatibility with both Piwigo 2.4 and Piwigo 2.5, replace mysql_fetch_array either by pwg_db_fetch_assoc or pwg_db_fetch_row.

Using mysql_fetch_array is not a good practice. Imagine the following code:


$query = '
$result = pwg_query($query);
while ($row = mysql_fetch_array($result))
  // what do we have in $row?
  // $row[0] == $row['id']
  // $row[1] == $row['name']

It is 99,93% sure that you use $row['id'] and you never use $row[0] in this kind of code.

With pwg_db_fetch_row you only get $row[0] and $row[1]
With pwg_db_fetch_assoc you only get $row['id'] and $row['name']

Depending on your code, use pwg_db_fetch_row or pwg_db_fetch_assoc

Thanks for reading. The full list of the technical changes in 2.5 is available there


  •  » Engine
  •  » [Piwigo 2.5+] use of mysql_* function is forbidden

Board footer

Powered by FluxBB

github twitter newsletter Donate © 2002-2022 · Contact