As other users have noted, the third and fourth bullet points are probably not worth holding on to, as it makes the first two difficult to implement:
use S : application "Safari"
property PHPMyAdminURL : "http://xxxxx/ppmya"
on run
if S is not running then return openPHPMyAdmin()
set _T to a reference to (every tab of every window of S whose ¬
name contains "PHPMyAdmin" and ¬
URL contains "/ppmya")
if (count _T) > 0 then return viewPHPMyAdmin(_T)
openPHPMyAdmin()
end run
to openPHPMyAdmin()
tell S
if (count windows) = 0 then
make new document with properties ¬
{URL:PHPMyAdminURL}
else
make new tab at end of tabs of S's window 1 ¬
with properties ¬
{URL:PHPMyAdminURL}
set current tab of S's window 1 to the result
end if
activate
end tell
end openPHPMyAdmin
to viewPHPMyAdmin(T)
set [T] to T
set W to the first window of S whose tabs contains T
set current tab of W to T
activate S
set the index of W to 1
end viewPHPMyAdmin
After some initial feedback from @user3439894, I removed the on quit
handler as trying to use the script as a stay-open application prevents item 2 from being effectively implemented.