I am new with web development. I have difficulty in connecting to an oracle DB. This code was patterned from the Oracle documentation.
I am sure with the connection details except the socket.Is the socket on default? or How do I get the socket detail from the Oracle DB interface?
$host="site.com";
$port=1404;
$socket="/tmp/mysql.sock";
$user="admin";
$password="admin123";
$dbname="admin_table";
/* create a connection object which is not connected */
$conn = new mysqli();
$conn -> init();
/* set connection options */
$conn -> options (MYSQLI_INIT_COMMAND, "SET AUTOCOMMIT=0");
$conn -> options (MYSQLI_OPT_CONNECT_TIMEOUT, 200);
/* connect to MySQL server */
$conn -> real_connect ($host, $user, $password, $dbname, $port, $socket)
or die ('Could not connect to the database server : ' . $conn -> error . '\n');
I also encounter these errors:
Warning: mysqli::real_connect() [mysqli.real-connect]: MySQL server has gone away in C:\wamp\www\Lot_Verification\pages\DB_Connect.php on line 19
Warning: mysqli::real_connect() [mysqli.real-connect]: Error while reading greeting packet. PID=6572 in C:\wamp\www\Lot_Verification\pages\DB_Connect.php on line 19
Warning: mysqli::real_connect() [mysqli.real-connect]: (HY000/2006): MySQL server has gone away in C:\wamp\www\Lot_Verification\pages\DB_Connect.php on line 19
Fatal error: Maximum execution time of 60 seconds exceeded in C:\wamp\www\Lot_Verification\pages\DB_Connect.php on line 20
Related
Trying to connect php to oracle 19c, using php 8.1, apache lounge, this is the code i am trying to run
// Create connection
$conn = oci_connect($username, $password, $servername);
// Check connection
if (!$conn) {
$e = oci_error();
echo htmlentities($e["message"]);
}
error message: Warning: oci_connect(): ORA-12637: Packet receive failed
I have download and set the enviroment variable of both the latest oracle instant client and the version 19_15. But still getting the same error message have also uncommented the dll files oci8_19 and pdo_oci.
<?php
$conn = new mysqli('localhost','root', '', 'votesystem','8080');
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
?>
Errors returned are:
Warning: mysqli::__construct(): Error while reading greeting packet. PID=14576 in
C:\xampp\htdocs\votesystem\admin\includes\conn.php on line 2
Warning: mysqli::__construct(): (HY000/2006): MySQL server has gone away in
C:\xampp\htdocs\votesystem\admin\includes\conn.php on line 2
Fatal error: Maximum execution time of 120 seconds exceeded in
C:\xampp\htdocs\votesystem\admin\includes\conn.php on line 2
My localhost runs on port 8080.
username-root
hostname=localhost
password=no
global privileges=ALL
PRIVILEGES Grant= yes
You have confused the Webserver with the MySQL Server. Your web server is running on port 8080, not your MySQL Server. The MySQL server runs on port 3306 (by default) so your web application needs to connect to it on that port.
Change your mysqli connect string to:
$conn = new mysqli('localhost','root', '', 'votesystem', '3306');
When I connect from localhost I get this error
Warning: mysqli::mysqli(): (HY000/2002): A connection attempt failed
because the connected party did not properly respond after a period of
time, or established connection failed because connected host has
failed to respond. in C:\xampp\htdocs\vici\index.php on line 9
Connection failed: A connection attempt failed because the connected
party did not properly respond after a period of time, or established
connection failed because connected host has failed to respond.
here is my code
$servername = "27.111.132.11";
$username = "root";
$password = "123";
$dbname = "test";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
MySQL connection driver does not get any meaningful server at the location of localhost. So use,
'hostname' => '127.0.0.1'
rather than
'hostname' => 'localhost'
I can't connect to my server. Here are the mistakes it gives me:
Warning: mysqli::__construct(): MySQL server has gone away in
C:\xampp\htdocs\www\PHP-Project\logic\db_connection.php on line 3
Warning: mysqli::__construct(): Error while reading greeting packet.
PID=8632 in C:\xampp\htdocs\www\PHP-Project\logic\db_connection.php on
line 3
Warning: mysqli::__construct(): (HY000/2006): MySQL server has gone
away in C:\xampp\htdocs\www\PHP-Project\logic\db_connection.php on
line 3
Fatal error: Maximum execution time of 30 seconds exceeded in
C:\xampp\htdocs\www\PHP-Project\logic\db_connection.php on line 3
This is my connection file:
define("HOST", "localhost:81");
define("DB_USER", "root");
define("DB_PASSWORD", "");
define("DB_NAME", "bulitfactory_person_cv");
$db_connection = new mysqli(HOST, DB_USER, DB_PASSWORD, DB_NAME);
if ($db_connection->connect_error) {
die("Connection failed. ".$db_connection->connect_error);
}
Please, help me!
try it to increase max_allowed_packet and restart the server
Add log_warnings=2 within [mysqld]section to your .ini/.cfg file, shutdown restart mysql and you should have maximum connection failure information in your error.log.
$db= mysqli_connect('localhost', "root", "root");
if(!$db) die("Error connecting to MySQL database.");
mysqli_select_db("onlineform", $db);
As I try to connect to the database like shown above, I am getting the following error:
Warning: mysqli_connect(): [2002] No such file or directory (trying to connect
via unix:///var/mysql/mysql.sock) in - on line 3 Warning: mysqli_connect():
(HY000/2002): No such file or directory in - on line 3 Error connecting
to MySQL database.
It's my first time using mysqli, I thought it would be a big improvement over mysql. I checked with MAMP if it's enabled and it is.
Any suggestions?
Check if your socket is correct. If not, override the default socket. I guess you have to try something like this in MAMP:
$link = mysql_connect(
':/Applications/MAMP/tmp/mysql/mysql.sock',
'root',
'root'
);