Platon Technologies
neprihlásený Prihlásiť Registrácia
SlovakEnglish
open source software development oslavujeme 10 rokov vývoja otvoreného softvéru! Pondelok, 30. november 2026
O nás
Magazín
Otvorený softvér
CVS
Služby
Index  »  Projekty  »  phpMyEdit  »  Fórum  »  Input restrictions from a sepereate SQL host?

phpMyEdit Configuration     Input restrictions from a sepereate SQL host?
Odoslať novú tému   Odpovedať na tému    
 
falz     Založený: 19.12.2006   Príspevky: 4  
Príspevok Zaslal: 2006-12-19 18:17
Návrat hore  Odpovedať s citátom     

Hello,

I've been using phpmyedit to ease the pain of administering some DB data for a while now. The input restrictions are great, and I frequently use them to restrict input to data that is found in another database.

However, I've come across a scenario that this doesn't work- if the table I'm looking up is a completely seperate SQL server.

So, normally I'd have something like this:

Kód:
  'values'   => array(
                'db' => 'somedatabase',
                'table' => 'customerinfo',
                'column' => 'accountno',
                'description' => 'company',
                'filters' => 'active = "1"'
        )


Which works fine and will use the same user/pass that's initially defined in phpmyedit. However, I thought I could be clever and try something like:

Kód:
  'values'   => array(
                'hn' => 'other.sqlserver.com',
                'un' => 'otherusername',
                'pw' => 'otherpassword',
                'db' => 'otherdatabase',
                'table' => 'customerinfo',
                'column' => 'accountno',
                'description' => 'company',
                'filters' => 'active = "1"'
        )


But this doesnt work. I randomly tried some other keywords instead of hn, un, etc, but they didnt work.

Looking at the class, I see that the set_values_from_table function seems to not have any information in it about a seperate host or username.

Has anyone tried this before? I'm attempting this because the database that contains the info I'm editing is a mail server, and it's getting things like usernames/passwords. I'm trying to link this to a list of customers that's on a completely seperate host.

I'm attempting to avoid making a copy of this customer database on this other host, and having to keep it up to date.

If anyone has any thoughts, let me know. If it's not possible in current code, I'm assuming I'd have to add a feature request?

--falz

 
ajh     Založený: 17.12.2003   Príspevky: 236  
Príspevok Zaslal: 2006-12-20 10:34
Návrat hore  Odpovedať s citátom     

Have you had a look at the 'dbh' option? It allows you to create your own database connection and just supply PME with a database handle rather than give the database etc.

http://opensource.platon.sk/projects/doc.php/phpMyEdit/html/configuration.general.html#CONFIGURATION.MYSQL-OPTIONS

Look at example 3.2

Having said this, 'hn' should work to connect to a different host. Are you sure that the name that you've used resolves?

 
falz     Založený: 19.12.2006   Príspevky: 4  
Príspevok Zaslal: 2006-12-20 16:11
Návrat hore  Odpovedať s citátom     

ajh Napísal:
Have you had a look at the 'dbh' option? It allows you to create your own database connection and just supply PME with a database handle rather than give the database etc.

http://opensource.platon.sk/projects/doc.php/phpMyEdit/html/configuration.general.html#CONFIGURATION.MYSQL-OPTIONS

Look at example 3.2

Having said this, 'hn' should work to connect to a different host. Are you sure that the name that you've used resolves?


I didn't see that $dbh option before, thanks. I'm actually using an IP in my real code, so DNS is a non-issue there.

However, what I'm trying to do is have two database handles, the second one is only used for a 'values' lookup.

Reading the syntax on that link, it appears that that's just used so that I don't have to hardcode database connecitons and passwords in each phpmyedit file (which is still nice)

I looked at adding this a few different ways (supplying dbh only inside the values portion):

Kód:
$accountlink = mysql_connect('dbserver', 'username', 'password');
$accountdb = mysql_select_db('dbname', $accountlink);
  'values'   => array(
                'dbh' => $accountlink,
                'db' => 'otherdatabase',
                'table' => 'customerinfo',
                'column' => 'accountno',
                'description' => 'company',
                'filters' => 'active = "1"'

I tried both of these lines seperately:
Kód:
'dbh' => $accountlink,
'dbh' => $accountdb,

but to no avail. When it connects, it always appears that it's not even reading this 2nd database connection, as I get some error similar to:

Kód:
SELECT command denied to user 'username'@'my.firewall.com' for table 'customerinfo'

where username ISN'T the username of this second conneciton.

So, from what I can tell, there appears to be no way for PME to use two seperate database handlers?

--falz

 
mmatos     Založený: 30.12.2006   Príspevky: 1  
Príspevok Zaslal: 2006-12-30 04:23
Návrat hore  Odpovedať s citátom     

Why not just create your own connection and drop what you need into an array, and pass that to PME?

Just drop this at the top of your script somewhere:
Kód:

$link2 = mysql_connect('localhost', 'mysql_user', 'mysql_password');
if (!$link2) {
   die('Could not connect: ' . mysql_error());
}

mysql_select_db('otherdatabase',$link2);
$query = "SELECT accountno FROM customerinfo WHERE active = 1";
$result = mysql_query($query,$link2);
while ($row = mysql_fetch_assoc($result))
{
  $accountvalues[] = $row['accountno'];
}
mysql_close($link2);


and then later in your code...

Kód:

'values' = $accountvalues;


 
falz     Založený: 19.12.2006   Príspevky: 4  
Príspevok Zaslal: 2006-12-31 19:45
Návrat hore  Odpovedať s citátom     

mmatos Napísal:
Why not just create your own connection and drop what you need into an array, and pass that to PME?

Thanks for the suggestion. I hadn't even thought of simply passing in an array there, I was only thinking of using built in phpMyEdit functionality. I tried what you suggested, and it worked like a charm!

The data I populate the table with is different from the text displayed in the <select> box, so I used a 'values2'. Just so the solution is clear for future forum readers, the code I put in place is the same as what you put above, except:

My while loop looks like this to get two fields:

Kód:
$query = "SELECT accountno, company FROM customerinfo WHERE active = 1 ORDER BY company ASC";
$result = mysql_query($query,$link2);
while ($row = mysql_fetch_assoc($result)) {
        $accountvalues[$row['accountno']] = $row['company'];
}


And the field values2 is:

Kód:
'values2'  => $accountvalues


This ends up giving an array that looks something like like:

Kód:
Array (
    [A6051949145%::IQREri] => ABC Industries
    [A0101361472&,%O7 Her] => Google
    [A1022058396%=V$*DAR] => Snake Oil Incorporated
    [A1032646585&;I:7DAcr] => Some other company name
)


.. and works perfectly. Hope this helps someone in the future as well.

--falz

 
Odoslať novú tému   Odpovedať na tému    

Copyright © 2002-2006 Platon Group
Stránka používa redakčný systém Metafox
Na začiatok · Odkazový formulár · Prihláška
Upozorniť na chybu na PLATON.SK webstránke · Podmienky použitia · Ochrana osobných údajov