Update query runs on local server but no on the internet - php

Please I need some brain storming. I created an update query as seen below.
<?php require_once('Connections/#####.php'); ?>
<?php
$result = mysql_query("UPDATE volunteers, vcodes SET volunteers.sn = vcodes.sn WHERE volunteers.vid = vcodes.id");
?>
It runs behind a form within a web application on my local server and produce the right result but when I upload it to the internet, it does not run but just sits there.
Can any one please help ascertain why it runs only on my local server but not on the internet. I am develop my application within Dreamweaver CS6.

1) As others have pointed out, mysql_XXX functions are obsolete. For new code, you should absolutely use the new MySQL APIs: either PDO or mySqli:
The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead
2) Similarly, you should use prepared statements. Not "update..." or "select *". Especially if your server is facing the internet!
http://www.php.net/manual/en/mysqli.quickstart.prepared-statements.php
3) By default, mySql is configured to allow local connections only. This is a Good Thing. In general, your Web server will face the internet ... but all SQL queries and updates will be local, between your Web Server and MySQL. This is both more secure and more efficient.
3) If you want to use MySQL remotely, you must do two things:
a) Configure a MySQL account to allow remote access
b) Open your server's firewall to the MySQL port
Here is an article that discusses how to do this:
http://www.rackspace.com/knowledge_center/article/mysql-connect-to-your-database-remotely

One of the reason may be your table and fields names are capitalized. You might be using windows in you local where they are not case sensitive and your remote server might be linux where table and field names are case sensitive. Make sure you are using lowercase letter for your fields and table names.

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.

MySQL - Double connection on two Databases?

This is just a quick question, I couldn't find it on the internet, but I did wanted to have a confirmation.
Say that if I, using PHP, want to connect to (for both the same) MySQL server, but I want to use two databases, not tables. Because you can connect to only one MySQL-database in the PHP mysqli_connect() command, will, connecting to two databases, though on the same server, use two connections.
Because then it'll probably go fast with the max_connections, right?
P.S. What was the SQL-command again to see the mac_connections value again? I thought it started with GET GLOBAL ... or something, but I might be wrong.
I do not have access to the server, only to (limited) FTP files (it's a bit irritating).
SHOW VARIABLES LIKE '%max_connections%'
If you have both databases in same server you can connect to the server and select one database. You can query from any other databases in the server as long as you have permission. Use the syntax databasename.tablename.columnname in your queries.
If your databases are in different server you may have to do little more work on the server side. you can use the The FEDERATED Storage Engine
I already found it, though I ran into it by pure accident mysqli_select_db().

is it necessary to use php to connect to the MySQL

is it necessary to use php to connect to the MySQL
i am working the desktop application and do not have a knowledge of php either
is there any in build class or functionality that can be use to connect to the MySQL
although there are many programme present over the internet to do so but unablefind one without the use of php. is there any reference or can i have the step by step example regarding the work.
MySQL config has the default settings. like username is root and password is blank my server name is local host.
No. PHP is a programming language. MySQL is a database. Install MySQL and type mysql from the command line and you will be connecting to MySQL using mysql.
MySQL docs
If you're writing a desktop application, mysql probably isn't the database you want to use. If you want to store data locally, try something like an embedded sqllite database. If you want to store the data remotely, I STRONGLY recommend to put the database behind an API. That is where something like PHP would come into play. It doesn't have to be PHP though. It can be python, java, ruby, etc.
Whatever you do though, DO NOT talk directly to a remote mysql database from your desktop app. That's just asking to have your db hacked.
MySQL has nothing to do with PHP, except that they are often bundled together. If you need to access MySQL by itself you can download MySql workbench.
http://www.mysql.com/products/workbench/
If you need a driver for your language google 'language + MySql Driver'

Trouble in PDO and sqlsrv land

I set up a site on my local system using PDO and a MySQL Database. I used PDO because when the site goes on the live server I have to user SQL Server and I was hoping PDO would take care of all my query conflicts.
Now that I'm up on the live server I get an error whenever the application uses the "LIMIT" function. I realize this is a MySQL specific function but shouldn't PDO take care of the conflict? How do I fix it so that site will work on MySQL and SQLSRV?
Thanks in advance.
Never develop in one technology expecting to use a different technology in prod.
It fails because there is no SQL Server equivalent for LIMIT so it can't convert.
If you expect different backends to be possible, use ANSII standard SQL not database specific things. If you expect to use only SQL Server in prod, develop in SQL Server (there is a free version).

Connecting to external MySQL DB from a web server not running MySQL

While I've been working with MySQL for years, this is the first time I've run across this very newbie-esq issue. Due to a client demand, I must host their website files (PHP) on a IIS server that is not running MySQL (instead, they are running MSSQL). However, I have developed the site using a MySQL database which is located on an external host (Rackspace Cloud). Obviously, my mysql_connect function is now bombing because MySQL is not running on localhost.
Question: Is it even possible to hit an external MySQL database if localhost is not running MySQL?
Apologies for the rookie question, and many thanks in advance.
* To clarify, I know how to connect to a remote MySQL server, but it is the fact that my IIS web server is not running ANY form of MySQL (neither server nor client) that is giving me trouble. Put another way, phpinfo() does not return anything about MySQL. *
Yes, you can use a MySQL database that's not on the same machine as Apache+PHP.
Basically, you'll connect from PHP to MySQL via a network connection -- TCP-based, I suppose ; which means :
MySQL must be configured to listen to, and accept connections on the network interface
Which means configuring MySQL to do that
And given the required privileges to your MySQL user, so he can connect from a remote server
And PHP must be able to connect to the server hosting MySQL.
Note, though, that habing MySQL on a server that's far away might not be great for performances : each SQL query will have to go through the network, and this could take some time...
If phpinfo is not returning anything about MySQL you need to install the MySQL plugin for PHP, easiest way to do that probably is to just upgrade PHP to the latest version. If not there is a .DLL file that you will need.
http://www.php.net/manual/en/mysql.installation.php
you will need to install the mysql extensions. this link should help: http://php.net/manual/en/install.windows.extensions.php
The MySQL server has nothing to do with PHP itself. What "mysql support" in PHP means is that it's been compiled with (or has a module loaded) that implements the MySQL client interface. For windows, it'd be 'mysql.dll', and on Unix-ish systems it'd be 'mysql.so'. Once those are loaded, then the various MySQL intefaces (mysql_xxx(), mysqli_xxx(), PDO, MDB2, etc...) will be able to access any MySQL server anywhere, as long as you have the proper connection string.

Categories