MySQL Server gone away in PHP - php

$mysqli = new mysqli("127.0.0.1:30", "root", "");
if ($mysqli->connect_errno)
{
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->
connect_error;
exit("..............");
}
This code executes a long time and in the end it says MySQL Server has gone away.
Apache Port is 30
MySQL server port is 3306
Using Microsoft Windows 8.1

you can also use this
$mysqli = new mysqli("127.0.0.1", "root", "");
mysqli.default_port=3306
this will connect by default through 3306 port.
check this

Related

Warning: mysqli_connect(): (HY000/2006): MySQL server has gone away

I am trying to write php to connect data from myqsl (i use free host 000webhost.com)
file connect:
<?php
$connect = mysqli_connect("files.000webhost.com:21", "nguyendang", "password", "foodcourt_db") or die ("could not connect to sever " . mysqli_connect_error()) ;
mysqli_query($connect, "SET NAMES 'utf8'");
?>
I had these errors when i ran
Try hostname with localhost. And also check the MySQL server is currently running.
This may happen in hosting for less duration due to overload of MySQL Server
Try to use this connection:
$link = mysqli_connect("localhost", "username", "password", "database_name");
//check connection
if($link === false) {
die("ERROR could not connect. " .mysqli_connect_error());
}

Connect to remotemysql.com on my website?

I want to connect a database on remotemysql.com too my website (ddu.nu/3/weatherstation). When i try to run the connection to the database on the website the connection fails. But when i try the exact same code on the localhsot the connection is created. Here is the code that i am using.
$connect = mysqli_connect("remotemysql.com:3306", "dbuser", "dbpass", "dbname");
if(!$connect ) {
die('Connection failed: ' . mysqli_error());
}
echo 'Connected successfully';
The website doesn't give any error.
Here is the website
And here is the localhost
My quetion is what I need to do in order for the real website to function.
You should try to disable ssl or the ssl have to have ssl cert, mine is work pefectly with ssl disable:
String dbURL = "jdbc:mysql://remotemysql.com:3306/";
Connection con = DriverManager.getConnection(dbURL + dbName + "?useSSL=false",
dbUsername,
dbPassword);

Connect RDS Database with PHP

I am new to Amazon Web Services. I am trying to connect the RDS but it is showing Error.
$db_hostname="RDSEndpointwithport";
$db_username="username";
$db_password="password";
$db_name="databasename";
$conn = mysqli_connect($db_hostname, $db_username, $db_password, $db_name);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
I felt issue with hostname. Can you try the RDS dns name without port in hostname variable?
the variable should be
$db_hostname="RDSEndpoint"

How do i connect the php file to connect database using IBM Bluemix?

I have some problem
code line
$servername="us--------03.cleardb.net";
$user="be9-------0";
$pass="f9-------";
$db="ad_50f-------fa6a";
$con = mysql_connect($servername, $user, $pass, $db);
mysql_select_db($db);
My Requirement
I implement this line code could not be working than how should be connect database in ibm bluemix!!
plz given me solution..
mysql_connect is deprecated.
Use this code as an example:
$mysqli = new mysqli($mysql_server_name, $mysql_username, $mysql_password, $mysql_database);
if ($mysqli->connect_errno) {
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
die();
}
Your composer.json needs to have:
{
"require": {
"ext-mysqli": "*"
}
}
https://github.com/IBM-Bluemix/php-mysql See: db.php and composer.json
To view the logs, use this command:
cf logs <yourappname> --recent

MAMP cannot connect to SQL server within a PHP script

I am quite new to the PHP world. I have installed MAMP on my Mac. This is the code I have written to connect to MySQL:
<?php
// Connect to the database server
$dbcnx = #mysql_connect("localhost", "root", “root”);
if (!$dbcnx) {
echo( "<P>Unable to connect to the " .
"database server at this time.</P>" );
exit();
}
?>
MySQL has already started and is running. I am not sure why am I not able to connect.
Try this
<?php
// Connect to the database server
$dbcnx = mysql_connect("localhost", "root", "");
if (!$dbcnx) {
echo( "Cannot connect to database due to ". mysql_error());
exit();
}
?>
Since you are getting Access denied for user 'root'#'localhost' (using password: YES) there is no need of giving password to connect with the database.So try with password ''.
Note:- mysql_* functions are deprecated as of PHP 5.5.0,and will be removed in the future.Instead, the MySQLi or PDO_MySQL extension should be used
Your code has smart quotes around the password. Try replacing them with regular quotes. If you have not changed the default MAMP password, this should work:
<?php
// Connect to the database server
$dbcnx = mysql_connect("localhost", "root", "root");
if (!$dbcnx) {
echo( "<P>Unable to connect to the " .
"database server at this time.</P>" );
exit();
}
?>

Categories