PHP & MySQL on Mac OS X: Access denied for GUI user - php

I have just installed and configured Apache, MySQL, PHP and phpMyAdmin on my Macbook in order to have a local development environment. But after I moved one of my projects over to the local server I get a weird MySQL error from one of my calls to mysql_query():
Access denied for user
'_securityagent'#'localhost' (using
password: NO)
First of all, the query I'm sending to MySQL is all valid, and I've even testet it through phpMyAdmin with perfect result. Secondly, the error message only happens here while I have at least 4 other mysql connections and queries per page. This call to mysql_query() happens at the end of a really long function that handles data for newly created or modified articles. This basically what it does:
Collect all the data from article form (title, content, dates, etc..)
Validate collected data
Connect to database
Dynamically build SQL query based on validated article data
Send query to database before closing the connection
Pretty basic, I know. I did not recognize the username "_securityagent" so after a quick search I came across this from an article at Apple's Developer Connection talking about some random bug:
Mac OS X's security infrastructure gets around this problem by running its GUI
code as a special user, "_securityagent".
So as suggested by Frank in the comments I put a var_dump() on all variables used in the mysql_connect() call, and every time it returns the correct values (where username is not "_securityagent" of course). Thus I'm wondering if anyone has any idea why 'securityagent' is trying to connect to my database - and how I can keep this error from occurring when I call mysql_query().

If username is not specified explicitly, MySQL tries to guess it by using name of current system user.
You don't have to accept that, you just need to specify desired username explicitly.
How – that depends how you're connecting. In case of phpMyAdmin it's config.inc.php, add line like:
$cfg['Servers'][0]['user'] = 'Eirik';
(see manual)

Did you set up your local AMP server using a pre-made package, or did you install MySQL, PHP, etc. through the respective OS-specific download packages? Setting up Apache, MySQL, and PHP4/5 can be a real PITA.
If you're having problems with your setup I'd recommend MAMP. It's a nifty all-in-one package that really does the trick. You can still access all the config files you want, and everything is contained in the MAMP folder instead of spread all over the system. If Apple upgrades the pre-installed version of Apache/PHP, your machine-specific config wouldn't be overridden as it would in the case of using pre-installed Apache/PHP.

Related

What to do about MS Access in PHP in Unix?

I need to pull data from MS Access 2007 (both mdb and accdb files) for a website written in PHP 7. The pages don't need to be dynamic or interactive. They just need to present data stored in the database.
Local development environment: Windows 7, IIS 7.5
Online server: A2 Hosting, Linux (CloudLinux Server release 6.9), Apache/2.2.34
The ADOdb webpage for Access says "Windows Yes, Unix No". I presume this means I can use ADOdb to connect to Access in my local environment, but not on the online server. I suppose I have the following options:
StackOverflow has some questions on this (1, 2, 3) with answers that give code for connecting to Access in PHP. Although the answers don't say so, I am guessing that that code will only work in Windows because if it were that easy to connect to Access in PHP in Unix, then ADOdb would do it! So if I'm right about this, then this is not a workable option.
The PHP Manual has a page on Database issues that says PHP can access Access, but it seems to only apply to either running in Windows or "running PHP on a Unix box and want to talk to MS Access on a Windows box". So this also does not appear to offer a workable solution for running the website online on a Linux server.
Extract the parts of the database needed into something else that can be accessed in Unix, such as CSV files, and use that as the database for the website. If I do this with CSV, I suppose I don't need ADOdb, but would just use fgetcsv(). This is an inelegant solution, but may be the best thing to do if there's not a way to access Access directly in Unix. (I could use MySQL instead of CSV, but that seems like a lot of unnecessary overhead.)
Run the pages on my Windows machine using ADOdb to access Access. Save the parts of the pages that come from the database as separate HTML segment files and include() them when the pages run online. (The script could detect which environment it's running in and if it's local, then access the database, and if online, then include() the HTML segment files.)
Move the online website from Linux to a Windows server, so PHP can access Access directly using ADOdb.
Convert the entire database from Access to something else, such as MySQL. This is not practical at this time, although that may be an option in the future.
Have I understood my options correctly? I've listed them in what seems to me to be the order of preference, so unless someone suggests otherwise, I guess I'll go with the third one (extract to CSV, use fgetcsv(), no ADOdb) since the first two won't work.
Thanks for your help.
The main problem is the ODBC driver. The {Microsoft Access Driver (*.mdb, *.accdb)} comes with Microsoft Access or the Microsoft Access Database Engine, which are both Windows-only.
However, there are alternate ODBC drivers that work on Unix and unixODBC. A popular open source one is mdbtools, which is limited, but can be used to connect Access to PHP on unix using PDO and ODBC. There are also commercial alternatives that are more fully featured.
Once you've got that working, it shouldn't be a problem to use the ODBC driver in PHP. Note that on shared hosting, this might not be possible.
Alternatively, you can use a php-jdbc bridge with UCanAccess. This might still be all-open-source and more fully-featured than mdbtools, but is more complex to set up correctly.
You don't need to convert "the entire database" from Access to use Mysql, just the tables. You can then link them back into the Access database using the MySql odbc connector and so long as the table names are the same you won't even notice the difference, all your forms, queries and everything will work.
You would then have MySql server running on your local machine which, if you create a user with the right permissions and port forward through your router (directing traffic from port 3306 or whichever port you assign to your server, to your machine) and allow the traffic through your firewall, your website can then access, read and write to your database.
If you want to query the database from php mysqli_query will work just fine. Most websites that run from data run using MySql, so this is a future proof solution too.

selecting data from IBM database while using wampserver

Good day,
I am using wampserver, and I would like to get data from a remote IBM database (AS400) using db2_connect. I've tried searching on some ways but I couldn't get the idea of doing it. I have successfully included ibm_db2.dll extension on my php. However, I don't know what to do next.
As you seem to be using "DB2 Connect" (and not a separate DB2 client) product you can either configure DB2-Connect with a node/alias/dsn and then mention that alias with the db2_connect() action, or use PDO_IBM longer connection string with all the details as mentioned here.
You need to know the tcpip-address (or hostname) of the i-Series DB2-server, and the Port-number it listens on.
Check this technote for the actions required to make a node/alias (I believe the same general configuration pattern applies to DB2-connect as Data server client).
The advantage of configuring like this is that you can verify the database-connect in your workstation command line shell , before making it work in PHP/pdo.

Can connect to database on server but cannot insert. Works on mamp localhost

I created a website which was fully functional on my computer's MAMP. When I placed it on the server, everything works well except for the fact that I cannot insert a new user into the DB. I'm partially concerned that the SSL cert is interrupting it, but I don't know enough about this to determine that. To troubleshoot this I did the following:
1. confirmed the connection works by returning row numbers and data that I manually placed into the database
2. confirmed openSSL is active/on
3. confirmed proper placement of my ssl certs through a separate site that confirms their presence
4. checked the error log on the server (which showed no errors) and then created a script to cause an error as proof of principle it works
5.confirmed the phpmyadmin user has full privledges
6. I have two user types and scripts that both don't work that worked on MAMP so I'm fairly confident its not poor coding
Further, all my php sql statements have built in mysqli_error($conn) which show no errors, and when I attempted a basic
"INSERT INTO users (name) VALUES ('john')"
scenario, it was unsuccessful.
My feeling that it is the ssl stems from the fact that my other (non-encrypted) sites don't have this problem. Is there something basic I'm missing?
Its not the SSL, its your configuration. See into it. If you can insert while doing it in the phpmyadmin with a raw sql, then check your config like the hostname user and db name. What server you are using?

No database selected on PHP MySQL

Error: No Database Selected
I have a website that was hosted with ARVIXE (windows 2008 server) and presently with IXWEBHOSTING (windows 2003 server). It was very simple to move. It was a matter to just download/upload the site PHP files and export/import MySQL database and change the config PHP file to point to the new
database information and voila!
Now I am trying to move the site to my own server. Trust me I have no problems with DNS, servers, networking stuff. I've being doing this for 15 years (not programming).
This is my actual server: Windows 2003 STD SP2, IIS6, PHP5.2.12, MySQL 5.0.96, FastCGI 1.5. and all MS Updates.
Now here me out before you conclude that is the code or MySQL permissions... I have read I think all the No Database Selected errors on the Internet including here and is usually a little code modification or missing code or permission issue on the database...but not this one, see the scenarios below and you will see why not.
Scenario 1
PHP Files are sitting in the IXWEBHOSTING servers. The config PHP file points to my own MySQL server it works fine.
Scenario 2
PHP Files are sitting in the IXWEBHOSTING servers. The config PHP file points to IXWEBHOSTING MySQL server it works fine.
Scenario 3
PHP Files are sitting in my Win2k3 servers. The config PHP file points to IXWEBHOSTING MySQL server, I get error "No database selected".
scenario 4
PHP Files are sitting in my Win2k3 servers. The config PHP file points to my own MySQL server, I get error "No database selected".
So I know for a fact it has nothing to do with MySQL permission on my own MySQL server or PHO code as scenario 1 proves it. It seems to be a problem with PHP on my server.
Prior of installing the OLD PHP and MySQ, I had the lastest version of each PHP 5.3.13 and MySQL 5.5.25 and same FastCGI version. I had the exact same problem!!!! The reason why I installed the old versions is because I wanted to match IXWEBHOSTING server versions.
Prior to the above installations, Windows was installed from scratch each time on a hyper-v server. No updates MS updates were done on the server the first attemps and the last installation it has all the MS updates and I still have the same problem.
I had the same problem with Windows 2008 STD, PHP 5.3.13 and MySQL 5.5.25.
PHP is loading all the proper extensions to make the connections to MySQL. I also have PHPmyAdmin running without problems.
I also tried with in the config file and no luck
There is a lot of stuff in the index but this is what is needed to make the connection to the database and the query and where it fails.
config file
<?
$usuarios_sesion="youth";
$host="localhost";
$user="usernamehere";
$pass="passwordhere";
$db="databasehere";
$tabla="users";
?>
Index.php File
<?
require ("enlaces_config.inc.php");
$menu=mysql_query("SELECT id_cat, name_cat FROM categories WHERE access=0 AND published=1") or die ("Can't select categorias MySQL says: ".mysql_error());
?>
At this point I have no idea what else it can be... permissions, maybe but not in MySQL permission, the user has full priviledges to the database. Scenario 1 and 2 proves it too.
If you need to check PHP information let me know. I will post the name of the php file for excution
Help!
The problem is not with all that you have written w.r.t your server.
When you try to fetch data from a database you must essentially follow these steps-
Create a connection
That involves connecting using Database, User Name, and Password, along with Hostname. You can use mysql_connect(), although deprecated.
You need to select the database from that host.
You go for any mysql query using selected db connection in step 2.
I would suggest you to get a good grip on database concepts first and then implementation using php.
Best place to start http://w3schools.com

Advantage and PHP - Error 6303: Maximum Advantage Database Server connections exceeded

My company php web site is connected to an Advantage Database Server where are stored all necessary data such as users, passwords and customer registry.
Lately we started to get an error requesting web pages:
Warning: SQL error: [Extended Systems][Advantage SQL][ASA] Error 6303: Maximum Advantage Database Server connections exceeded. axServerConnect, SQL state HY000 in SQLDriverConnect in C:\...\www\... on line...
It's becoming critical day by day and it can happen once a week or twice a day without an apparent reason.
When website crashes, database service still working great with other applications connected and the only way to restore web service is to restart apache web server.
On database server we've got ads.ini configuration file in C:\Windows folder where we raised max connections setting with "MAX_CONNECTIONS=1000" which is really big compared to our needs.
Can it be useful if we set also "RETRY_ADS_CONNECTS = 1" ??
I found this post where R&D confirms a bug in may 2009:
Is this a bug with Advantage Database?
Has this been fixed? In wich release?
Where can i see the real number of connections open by apache on db?
Each php page closes ads connection on footer, what can cause connections to exceed??
Thanks in advance for help.
-
ENVIRONMENT INFO
Database:
Advantage Database Server 10.10.0.6 on Windows 2003 server
Web server:
Apache/2.0.59 (Win32) mod_ssl/2.0.59 OpenSSL/0.9.8d PHP/4.4.7 on Windows XP pro
On phpinfo() page we get "Advantage Version" "8.00.0.0".
Why this? Do we need to upgrade php-advantage extension?
Lots of questions, but I will try and address each.
1) 6303 Error. Using MAX_CONNECTIONS is the correct way to resolve this.
Make sure MAX_CONNECTIONS is in the [SETTINGS] section
Check if Apache / PHP / ADS driver is using the correct ads.ini file. You can use Process Monitor from Sysinternals to see what ads.ini file was opened successfully. If you upgrade your PHP driver you can set an environment variable adsini_path to point to the directory where the ads.ini lives.
2) Setting RETRY_ADS_CONNECTS=1 will be helpful. This also goes under the [SETTINGS] section of the ads.ini. When an ADS client receives a networking error (generally a 6000 class error) then the error is cached by the client driver and subsequent attempts to connect will use the cached error vs. retrying. Setting RETRY_ADS_CONNECTS will tell the ADS client to ignore the cached error and retry the connection
3) Bug: Looks like this was fixed in 9.10.0.9 version of the driver based on the release notes on http://devzone.advantagedatabase.com.
Fixed an issue where the garbage collection reference count on a
connection would be incorrect if multiple SQL statements were opened
on it.
Since you are running a 10.1 server you may look at updating to a 10.1 client which will also contain the fix. 10.1 Advantage PHP Driver
4)See the real number of connection
I would recommend using the stored procedure sp_mgGetConnectedUsers, you can use ARC (Advantage Data Architect) but it can be difficult to group, order, etc.
Since you are using 10.1 you can include the results of the stored procedure in a query such as
SELECT COUNT(*) FROM (EXECUTE PROCEDURE sp_mgGetConnectedUsers()) u WHERE ADDRESS='xxx.xxx.xxx.xxx'
You could also use other fields to identify the PHP application such as UserName (the server name), DictionaryUser (assuming the php application uses a unique user), ApplicationID
5) PHPINFO shows Advantage Version of the Advantage PHP client driver. You may want to upgrade the client driver for reasons mentioned above. Should be as simple as swapping DLL files (ace32.dll, axces32.dll, adsodbc.dll and php_advantage.dll), but I would recommend testing first to ensure you get everything.

Categories