I am unable to make a database connection from the App Engine SDK server to my local MySQL which was installed with MAMP. I understand that this is about the MySQL socket file which is in MAMP. How can I let App Engine SDK to listen to the local MySQL? I also want to ensure that my MAMP setup remains intact. Thanks.
App engine SDK for php can connect to you local MySql server in your development environment.
First make sure you have the latest SDK for PHP version, currently release 1.8.6.
Make sure your local MySql server instance is running and listening on port 3306.
Add your application in the App Engine SDK Launcher, click on it and select Edit / Application Settings and add in the "Extra Command Line Flags" field the following:
--mysql_user=user
Where user is the username to connect to your database.
Then you have to connect to your DB from your php code, in my case, I'm using PDO.
Like this:
try {
$db = new PDO('mysql:unix_socket=/cloudsql/<appname>:my-cloudsql-instance;charset=utf8;dbname=<yourdbname>','<user>','<password>');
syslog(LOG_DEBUG, 'Connected to database.');
} catch (PDOException $e) {
syslog(LOG_ERR, 'Failed to get PDO DB handle: ' . $e->getMessage());
print_r($e->getMessage());
exit;
}
Replace the text with <> tags with your application and MySql server settings.
GAE currently does not allow connection to any remote MySQL server. This is their limit and nothing to do with your setup.
Use their Cloud SQL instead.
I don't know in which situation the error occurred to Nagarjun, but to me happened with the following PHP warning
Warning: mysql_connect(): No such file or directory in
/Users/Aerendir/Documents/JooServer/_SandBox/GoogleAppEngine/continuous-wordpress-cms/wordpress/wp-includes/wp-db.php
on line 1372
In my situation, i were trying to install WordPress on Google AppEngine following their tutorial.
The problem was the hostname I used: localhost instead of 127.0.0.1
Using 127.0.0.1 as hostname solved the problem.
The solution was found here: Configuring MySQL connection in Google App Engine PHP SDK on Windows 7
Related
I am trying to connect to a MySQL database through PHP's PDO. It works fine on my home network and some other networks (coffee shops, public internet). When I try to connect through my phone's personal hotspot or through hotel wifi, it no longer works.
I am using the same login information across all of these with the same machine setup (XAMPP VM - Mac). This is my connection file:
$DBO = "mysql:host=$DB_Servername;dbname=$DB_Name";
try {
$conn = new PDO($DBO, $DB_Username, $DB_Password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
echo "Connection Failed: " . $e->getMessage();
}
This is the error I am getting:
Connection Failed: SQLSTATE[HY000] [2002] Connection timed out
I've tried the server name with the website address and the ip address. The strange thing is when I'm using the VS code database extension, I am able to connect to the database fine (no matter the network I am on). I can't figure out why that would be working but the PDO wouldn't be.
I read this answer about adding a space after 'mysql: ', and it returns this new message:
Connection Failed: SQLSTATE[HY000] [1045] Access denied for user 'dailyrts_realDB'#'localhost' (using password: YES)
The user account I am logging in with is assigned to the correct database and the new IP's I connect to are being registered.
dns_get_record returns:
dns_get_record(): A temporary server error occurred.
I wasn't able to find a fix using XAMPP-VM however, the same code works perfectly when using the XAMPP Installer version of the app on MacOS. I looked around for a bit to see if anyone else was having this problem and I didn't find anything that matches this issue specifically. Most were referring to connecting to a local database.
This answer about accessing MySQL through the root user is pretty close to the issue I was having and they recommend following this guide to fix the issue. I don't need to have the VM version installed so I haven't tested this myself however, it seems to have worked for him.
I'm not sure why the VM version only works on some networks and not others when connecting to MySQL databases. I'm sure this has something to do with port blocking on the network's end (mobile hotspot providers are notorious for blocking ports) and because the VM version handles network traffic differently from the regular version.
It looks like issues with the VM version are not isolated to this specific issue on MacOS. In my personal experience (and others), I'd recommend going with the installer version if you are able to. It is more developed and has more online support surrounding it.
I'm using Microsoft Azure SQL for my database and I'm trying to connect it to my project on my localhost using XAMPP. When I try to connect to the database using the connect string they provided:
try {
$conn = new PDO("sqlsrv:server = tcp:app.database.windows.net,1433; Database = mydatabase", "{myusername}", "{your_password_here}");
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch (PDOException $e) {
print("Error connecting to SQL Server.");
die(print_r($e));
}
I keep getting this error:
Error connecting to SQL Server.PDOException Object ( [message:protected] => could not find driver
The error is longer but I think it's related to the driver mentioned at the end. I'm using a mac so any driver I need to install would need to be compatible with it. Thank you for the help in advance.
Azure SQL Database is built on the Microsoft SQL Server engine. So you might consider using pdo-dblib to connect to SQL Server using the PDO on a Mac. You can check out a Stack Overflow question about it here or refer to this setup documentation.
After the driver having been installed, Azure SQL won’t actually accept connection from your local yet. And you might get the following error:
Client with IP address '167.xxx.xxx.xxx' is not allowed to access the
server.
That’s because there is a firewall in the way by default. To enable access, go to the Azure portal, click on All Resources, select your SQL service, click on Firewall in the SETTING menu.
Your client address is conveniently included in the list, so you can just click on Add client IP followed by Save.
Well, when you run your code now, it should connect.
I used odbc_connect() in my PHP page to connect to the HANA database. It works fine when i run it locally.
I upload the same PHP page into the server and i am getting this error:
Fatal error: Call to undefined function odbc_connect()
The code:
$connect = odbc_connect("Team6DataSource", "TEAM6", "Password1", SQL_CUR_USE_ODBC);
Team6DataSource = datasource name.
ip address = 54.217.234.218
Can any one please help me?
Thanks
I just go through in google get this instruction this is really helpful for you.
Download the SQL Server ODBC driver for your PHP client
platform. (Registration required.) If the SQL Server ODBC driver
is not currently available for your platform, check the list of
ODBC-ODBC Bridge Client platforms. The ODBC-ODBC Bridge is an
alternative SQL Server solution from Easysoft, which you can
download from this site.
Install and license the SQL Server ODBC driver on the machine where
PHP is installed. For installation instructions, see the ODBC driver
documentation. Refer to the documentation to see which environment
variables you need to set (LD_LIBRARY_PATH, LIBPATH, LD_RUN_PATH,
SHLIB_PATH depending on the driver, platform and linker).
Create an ODBC data source in /etc/odbc.ini that connects to the
SQL Server database you want to access from PHP. For example, this
SQL Server ODBC data source connects to a SQL Server Express instance
that serves the Northwind database:
Use isql to test the new data source. For example:
cd /usr/local/easysoft/unixODBC/bin
./isql -v MSSQL-PHP
[MSSQL-PHP]
Driver = Easysoft ODBC-SQL Server
Server = my_machine\SQLEXPRESS
User = my_domain\my_user
Password = my_password
Please copy and paste this script and execute this
<?
/*
PHP MSSQL Example
Replace data_source_name with the name of your data source.
Replace database_username and database_password
with the SQL Server database username and password.
*/
$data_source='data_source_name';
$user='database_username';
$password='database_password';
// Connect to the data source and get a handle for that connection.
$conn=odbc_connect($data_source,$user,$password);
if (!$conn){
if (phpversion() < '4.0'){
exit("Connection Failed: . $php_errormsg" );
}
else{
exit("Connection Failed:" . odbc_errormsg() );
}
}
// This query generates a result set with one record in it.
$sql="SELECT 1 AS test_col";
# Execute the statement.
$rs=odbc_exec($conn,$sql);
// Fetch and display the result set value.
if (!$rs){
exit("Error in SQL");
}
while (odbc_fetch_row($rs)){
$col1=odbc_result($rs, "test_col");
echo "$col1\n";
}
// Disconnect the database from the database handle.
odbc_close($conn);
?>
Replace data_source_name, database_username and database_password
with your SQL Server ODBC data source, login name and password.
To run the script under Apache, save the file below your Apache web
server’s document root directory. For example,
/var/www/apache2-default/php-mssql-connection.phtml. Then view the
file in a web browser:
http://localhost/php-mssql-connection.phtml
If your web browser is not running on the same machine as the web
server, replace localhost with the web server’s host name or IP
address.
To run the script from the command line, save the file.
For example,
/tmp/php-mssql-connection.php. Then run $ php
/tmp/php-mssql-connection.php.
further more Details Refer this LINK
Download this, copy the .dll to PHP folder and in the php.ini file add:
extension=php_sqlsrv_7_ts_x64.dll
extension=php_pdo_sqlsrv_7_nts_x64.dll
I just started learning PHP and MySQL, and I got stuck when trying to connect to my database from a PHP block. I have installed XAMPP and SQL Server Express 2012 on my machine. My server name is RAFAL-MAC and I selected 'Windows Authentication.'
I have a simple HTML page with PHP code in a file called search.php
the PHP code is
<?php
$con = mysql_connect('RAFAL-MAC','RAFAL-MAC\Rafal','');
if (!$con)
{
die( 'Could not connect: ' . mysql_error() ) ;
}
mysql_select_db("one", $con) or die(mysql_error());
?>
When I go to localhost:8080/search.php I get the following warning:
Warning: mysql_connect(): Host 'xxx.xxx.xxx.xxx' is not allowed to connect to this MySQL server in C:\xampp\htdocs\search_submit.php on line 11
Could not connect: Host 'xxx.xxx.xxx.xxx' is not allowed to connect to this MySQL server
I tried searching similar problems online, but all of the threads are about remote connections. I am just trying to connect to my local SQL server.
Any hints? I apologize for any missing information. Thanks! :)
EDIT:
I changed the server name to 'localhost'
Now I am getting this:
Access denied for user ''#'localhost' to database 'one'
Since you'd like to connect to SQL Server Express 2012, all functions beginning with mysql* will fail - since these functions speak to MySQL servers.
Please install Microsoft's MS SQL Server driver pack found here. From this page:
Perform the following steps to download and install the Microsoft
Drivers for PHP for SQL Server:
Download SQLSRV30.EXE to a temporary directory
Run SQLSRV30.EXE
When prompted, enter the path to the PHP extensions directory
After extracting the files, read the Installation section of the SQLSRV30_Readme.htm file for next steps
People in Microsoft's PHP driver forum should easily be able to answer your question, in case you still have problems after the installation of the driver.
Additionally, if connecting to the local machine, try to use these addresses:
localhost
127.0.0.1
These two addresses always reference the local machine.
I am having issues connecting to a mssql server that is located on a network machine. I need to connect remotely through another domain example (abc.com) not on the network to access data. This domain runs mysql if that makes any difference. I am trying to access the mssql server through this php script:
<?php
$server= 'ip address:port';
$user='user';
$password= 'pass';
$con = mssql_connect($server,$user,$password);
if (!$con)
{
die('Could not connect:' . mssql_get_last_message() );
}
else{ echo 'connected';
}
I run this script through the shell on abc.com and I get:
mssql_connect(): Unable to connect to server:
I have gone through several tutorials to enabling tcp/ip access through the sql server config manager as well as allowing the specific port through the firewall.
What are some other things I should try or steps I am missing here.
Also: the ip address I am using is the one I found in the sql server config manager-> protocols for SQLEXPRESS->tcp/ip_>ip addresses->IP2->ip adress it is the correct ip address? Where can I find it if not? I am not using the localhost 127.0.0.1
In short to successfully execute the cmd.
config:
(2 instances of SQL // SQL2005 + 2008 Express instance on the remote machine, which refuses to install Management Studio 2008.
1. Enable TCP/IP Protocol
2. Enable Named Piptes
3. started sqlcmd Utility with -s \SQLEXPRESS to get the right sever-instance
C:\Program Files\Microsoft SQL Server\100\Tools\Binn
4. Go to SMSS and local sql instance properties -> Connections -> check "Allow remote connections to this server" and run this script.
EXEC sys.sp_configure N'remote access', N'1'
GO
RECONFIGURE WITH OVERRIDE
GO
Here the link for the info from Msdn:
http://msdn.microsoft.com/en-us/library/ms162773.aspx
http://msdn.microsoft.com/en-us/library/ms162816.aspx
Thanx