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).
Related
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.
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().
This seems to be a fairly common question but looking at the help & solutions for other related threads hasn't helped me.
I'm using the PHP code block here (http://pastebin.com/xSJYyC3y) to try to connect and query a SQL Server database. The connection seems to work, but when making a query, I get the following error message:
[Microsoft][SQL Server Native Client 11.0][SQL Server]The server principal "my_username" is not able to access the database "database_name" under the current security context.
I only get this error when connecting to the server via PHP, if I do it manually through the MS SQL Management Studio, then everything works fine.
I am using Windows 7 x64, SQL Server 2008 SP1 x64, and PHP 5.4.
Thanks for looking at my problem!
If you can run the query through SSMS, but get a security issue through PHP, you are most likely experiencing an issue with wrong impersonation.
Generally, you'll have two different security issues in play:
The SQL Server's internal security - if you are logging on to the server with a SQL Server account and you are able to run the query from within SSMS using the same account as from PHP, the SQL Server security should be ok. If you cannot use the same account, start looking into roles and security on the server, temporarily relaxing the security for the account used by PHP.
Windows security: If the connection from PHP is not configured properly, you may see problems with impersonation. The most thorough explanation of this I've seen can be found through Brian Swans answer here.
Do note that if your query touches several databases, or especially if it includes something that explicitly touches the filesystem (perhaps on a shared folder), you need to check rights on all servers and all folders that are in play.
Also, if you are executing a stored procedure, make sure that you don't have the issue with EXECUTE AS OWNER. One example of this can be seen here
If that doesn't help you could still look into the security of the database files on your Windows box and try to - temporarily - relax the security to the folder to see if that changes anything.
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'
I'm trying to access the mssql database of my website which a web design team has designed. They have given me the ip, port, db name, user and password... but how can I connect to the mssql server?
I have tried doing it via php but I think I have to compile php without "--without-mssql" "--without-pdo-mssql"... which I would not rather do on this windows 7 computer unless I have to.
I've tried SQL Server Management Studio Express but I couldn't find a way to access to a REMOTE database.
I've also tried Razor SQL but that did not connect either.
I almost tried something like phpmyadmin for asp.net but wanted to find an easier solution for this- without installing asp.net.
So what would be a good solution for managing a remote mssql database? Is there a program like Office Access that can handle such job?
SQL Server Management studio does support remote connections, in the small dialog you see in the middle of the screen when you run it, specify IP, username and password.
do you get any error? Which error do you get?
I am a fan of Navicat:
http://www.navicat.com/en/products/navicat_sqlserver/sqlserver_detail_win.html
However, I have not used the Sql Server version, but the MySQL and Oracle versions are pretty good - MySQL is awesome (mid range price point is the only draw back).
However Navicat Lite, which is still pretty good (and can handle most server types) is free!
Just a note, has the remote DB been setup for remote connections? If not you will not be able to get access no matter what you use.