Am trying to connect with my database using php from my website. I have used following codes to make connection,
$db_host="10.12.209.82";
$db_username="username";
$db_pass="pass";
$db_name="DBName";
mysql_connect($db_host,$db_username,$db_pass) or die("Could not connect to my sql");
mysql_connect($db_name) or die("No Database");
But when i run the file in my website it shows the following error...
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator to inform of the time the error occurred and of anything you might have done that may have caused the error.
More information about this error may be available in the server error log.
What was the issue and where I made mistake?
don't use mysql its already deprecated use MySQLI or PDO instead..
USING MySQLI you can connect to your server just doing this..
define('HOST','10.12.209.82');
define('USER','username');
define('PASSWORD','password');
define('Database','dbname');
$dbh = mysqli_connect(HOST,USER,PASSWORD,DATABASE) or die('Cannot connect to the server');
Should be (mysql_select_db):
$db_host="localhost";
$db_username="root";
$db_pass="302010asd";
$db_name="mvnodb";
mysql_connect($db_host, $db_username, $db_pass) or die("Could not connect to my sql");
mysql_select_db($db_name) or die("No Database");
Invoking mysql_connect again and not supplying properly parameters raises a error.
Related
I have a website that I should put on my domain.I have encountered an issue when I tried connecting to MySQL database so my code is not working. When I put
define("DB_HOST","http://domain");
define("DB_USER","user");
define("DB_PASS","password");
define("DB_NAME","dbName");
$connection = mysqli_connect(DB_HOST,DB_USER,DB_PASS,DB_NAME);
if(!$connection){
die();
}
mysqli_set_charset($connection,"utf8");
I get this error in log
Failed to connect to MySQL: Plugin http could not be loaded: /usr/lib64/mysql/plugin/http.so: cannot open shared object file: No such file or directory
otherwise, I tried to remove that HTTP and just use the domain as DB_HOST, but then I get error
define("DB_HOST","mydomain.com");
define("DB_USER","user");
define("DB_PASS","password");
define("DB_NAME","dbName");
$connection = mysqli_connect(DB_HOST,DB_USER,DB_PASS,DB_NAME);
if(!$connection){
die();
}
mysqli_set_charset($connection,"utf8");
PHP Warning: mysqli_connect(): (HY000/2002): Can't connect to MySQL server on 'domain.com' (115) in /home3/domain/public_html/a/i.php on line 7
Can anyone please help me find the solution to make this work?
Here's how I define a MYSQLI connection;
$con = mysqli_connect("localhost","username","password","database");
When you want to run an operation you just invoke the $con variable.
If you have issues check the permissions for the MYSQL user, they should at the very least include;
delete
insert
select
show view
update
I'm a PHP newbie. I'm trying to connect to GAE using PHP and PDO. I have tried connecting using mysql_connect() and mysql_select_db(). I have been successful. However when I try to connect using PDO, I get an error
Connection failed: SQLSTATE[HY000] [2002] No connection could be made because the target machine actively refused it.
My code is as follows:
define('DBH_SOCKET', '/cloudsql/****:****');
define('DBH_NAME', 'wordpress_db');
define('DBH_USER', 'censored');
define('DBH_PASSWORD', 'censored');
$pdo_conn = "mysql:unix_socket=".DBH_SOCKET.";dbname=".DBH_NAME.";charset=utf8";
try {
$dbconn = new PDO($pdo_conn, DBH_USER, DBH_PASSWORD);
$dbconn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}catch (PDOException $e){
echo 'Connection failed: ' . $e->getMessage();
}
echo "<br> var is ".$pdo_conn;
/*$conn = mysql_connect(DBH_SOCKET, DBH_USER, DBH_PASSWORD);
if (!$conn)
die('Connect error ('.mysql_error());
$db_selected = mysql_select_db(DBH_NAME, $conn);
if(!$db_selected)
die('Cant use db: '.mysql_error());*/
What am I doing wrong? I have looked at some tutorials on the net like, http://webandphp.com/WorkingwithPHPontheGoogleCloudPlatform-166942. They use PHPStorm and a JDBC driver. However, there is no mention of using a JDBC driver in the official google tutorials.
When connecting using PDO locally, you'll need to use a connection string that matches your local MySQL server settings, e.g. "mysql:host=localhost;dbname={db name};charset=utf8".
When running on GAE, your current connection string should work fine. The fact that you're getting the error message "Unable to find the socket transport "unix" - did you forget to enable it when you configured PHP?" suggests that you might have missed the "unix_socket=/cloudsql/{project id}:{instance id}" part.
For some reason I can't connect to a Microsoft SQL database and the error I'm being presented with:
Warning: mssql_connect(): Unable to connect to server:
mssql2012.netregistry.net in
/clientdata/apache-www/q/u/quest.org.au/www/phpinfo.php on line 47
... Really doesn't help me to work out why at all.
Is there a way to display more detailed error messages? I have the following already in my code:
// Errors, errors everywhere
error_reporting(E_ALL);
ini_set('display_errors', 1);
But can my die statement in my connection string be expanded to provide me with more detail?
// Connect damn you.
$handle = mssql_connect($host, $username, $password) or die("Cannot connect to server")
We are using the below script.
Actually our DB is in one server (say www.server1.com) and the PHP file
containing the below connection string is in another server (say
www.server2.com)
If we place the PHP file containing the below script in the same server
where the DB exists that is www.server1.com/dbconnection.php it is working
fine.
But if we place the PHP file containing the below script in another server
www.server2.com/dbconnection.php it is not working. This displays the
error 'Something went wrong while connecting to MSSQL' Please advise.
Also to handle error if we use 'die('MSSQL error: ' .
mssql_get_last_message());' nothing displays just an empty page.
Please advise how to handle errors.
Script (dbconnection.php)
$server = 'xxx.xxx.xxx.x,xxxx'; //IP, Port
// Connect to MSSQL
$link = mssql_connect($server, 'username', 'password');
if (!$link) {
die('Something went wrong while connecting to MSSQL');
}
// Connect to DB
$db=mssql_select_db("databasename",$link) or die("Unable to select
database ");
Thank You
How to get error message, I do not know, but if you are migrating your PHP app from windows server to linux (FTP servers are more usual on linux), you can try change:
$server = 'xxx.xxx.xxx.x,xxxx'; //IP, Port
to
$server = 'xxx.xxx.xxx.x:xxxx'; //IP: Port
As described in first parameter of manual: http://www.php.net/manual/en/function.mssql-connect.php
When I' m trying to connect Sftp from my joomla site
its not connecting:
$c = ftp_connect('ftp.xyz.com') or die("Can't connect");
ftp_login($c, 'username' , 'pwd') or die("Can't login");
in this case msg showing Can't connect
I also tried this code
$connection = ssh2_connect('ftp.xyz.com', 22);
if (!$connection) die('Connection failed');
in this case no error msg showing
Please help me, if there is a proper solution help me please.
Thanks
ftp_connect() uses FTP, not SFTP. They're very different. So if your host is providing only SFTP, then no, that function won't work! SFTP is explained in more detail here:
http://en.wikipedia.org/wiki/SSH_File_Transfer_Protocol
ssh2_connect() is the right connection method to use, which is why it's probably working. You can see all the SSH2 functions available in PHP here:
http://php.net/manual/en/ref.ssh2.php
You'll probably be most interested in ssh2_scp_recv() and ssh2_scp_send() (for getting and sending files).