• Forum
  • Doc
  • Screenshots
  • Download
  • Donate
  • Contributors
  • Contact
  • Follow @phpfreechat
  • DEMO
  • Board index ‹ Version 1.x branch ‹ General Support (v1.x)
  • Change font size
  • FAQ
  • Register
  • Login

mysql container fix

Moderators: OldWolf, re*s.t.a.r.s.*2

Post a reply
3 posts • Page 1 of 1

Postby vlzvl » Mon Dec 26, 2011 6:10 am

hello there,
i found that the mysql container code contains some deprecated calls, specifically
this in line 109 of mysql.class.php
Code: Select all
    $db_list = mysql_list_dbs($db);
    while (!$db_exists && $row = mysql_fetch_object($db_list))
      { $db_exists = ($c->container_cfg_mysql_database == $row->Database); }

Im using a server that has PHP 5.4.0+ and according to following page:
php.net/manual/en/function.mysql-list-dbs.php
the "mysql_list_dbs" is deprecated, leading to a bug that PFC cant check the existence
of a previously created database, which further leading to re-creation of database by pfc,
producing the final error "mysql container: error on creating database; database already here"
or something similar...

I fixed this problem by using this simpler code (instead of the above function)
Code: Select all
    $db_selected = mysql_select_db($c->container_cfg_mysql_database, $db);
    if (!$db_selected) {
       die ('Mysql container:' . mysql_error());
    } else { $db_exists = TRUE; }

the above tries at first to connect to the database specified in php script, and if that
fails then PFC tries to create the database; otherwise db is selected & $db_exists becomes TRUE,
bypassing the creation. Note that the problem arises in first place by the above deprecated
function,

* This stuff works on servers where CREATE DATABASE privilege is locked.
** ..but if the user didnt already created his database by-hand he would still have problem,
because of database creation that PFC is doing by itself (i think its bad..; let users create it and
just select it in pfc code)
Last edited by vlzvl on Mon Dec 26, 2011 6:25 am, edited 1 time in total.
vlzvl
New member
 
Posts: 9
Joined: Sat Dec 17, 2011 2:24 pm
Top

Postby vlzvl » Mon Dec 26, 2011 11:08 am

The first code fragment (in pfc source) is for setting the $db_exists to TRUE, to know if a database is to be created or not.
The second fragment do the same thing (you replace it in whole) but without calling a possibly-deprecated code
(depends on server configuration)
The purpose is to check whether the given database name exists or not.
A call to "mysql_select_db" will return TRUE if the database's selection was successful, which sets
$db_exists = TRUE and replace nicely the first snippet work without actually reading/checking all databases in servers in a loop.
I encountered cases where server's configuration has restricted calls like "CREATE DATABASE" or "SHOW DATABASES",
if you get my meaning..

EDIT:
after some rechecking, i suppose the following line:
Code: Select all
$db_exists = mysql_select_db($c->container_cfg_mysql_database, $db);

is enough..
Last edited by vlzvl on Mon Dec 26, 2011 11:15 am, edited 1 time in total.
vlzvl
New member
 
Posts: 9
Joined: Sat Dec 17, 2011 2:24 pm
Top

Postby OldWolf » Mon Dec 26, 2011 9:03 pm

That's a spam bot, just ignore him... I'm deleting that account.

Thank you for your fix. :)
Signature:
Read before Posting: Forum Rules
Note: I am unable to offer support through PM/e-mail at this time.
OldWolf
Site Admin
 
Posts: 1918
Joined: Sun Sep 23, 2007 5:48 am
Top


Post a reply
3 posts • Page 1 of 1

Return to General Support (v1.x)

Who is online

Users browsing this forum: No registered users and 7 guests

  • Board index
  • The team • Delete all board cookies • All times are UTC + 1 hour
Powered by phpBB® Forum Software © phpBB Group
Sign in
Wrong credentials
Sign up I forgot my password
.
jeu-gratuit.net | more partners
Fork me on GitHub