php warning when logging in website folder by cpanel - php

I am writing some php script in the cpanel. When I access the website folder
(e.g. www.bbbbbb.com/folder/)
It give the warning like that.
Warning: mysqli::mysqli() [mysqli.mysqli]: (HY000/2005): Unknown MySQL server host 'host07.portalwebhosting' (1) in /home/restaur/public_html/restaurant/variables/variables.php on line 7
Warning: mysqli::set_charset() [mysqli.set-charset]: Couldn't fetch mysqli in /home/restaur/public_html/restaurant/includes/connect_database.php on line 3
Warning: mysqli::stmt_init() [mysqli.stmt-init]: Couldn't fetch mysqli in /home/restaur/public_html/restaurant/includes/login_form.php on line 45
Fatal error: Call to a member function prepare() on a non-object in /home/restaur/public_html/restaurant/includes/login_form.php on line 46
And I use the default account admin to access, it gives me the same result.
And here is my php coding
<?php
// database configuration
$host ="host07.portalwebhosting.com";
$user ="user";
$pass ="password";
$database = "monkey";
$connect = new mysqli($host, $user, $pass,$database) or die("Error : ".mysql_error());
// access key to access API
$access_key = "12345";?>

check your connection string or may be you need to try with port
$connection = new mysqli("host", "user", "pwd", "db", "3306");
no need to change port 3306 is default
why you use die("Error : ".mysql_error()); use mysqli

Related

Error in my code but i cant find out how to fix

Not able to connect to the database.
My error:
[Sat Jul 29 23:02:56.747139 2017] [proxy_fcgi:error] [pid 13049:tid 140689614522112] [] AH01071: Got error 'PHP message: PHP Warning: mysqli::mysqli(): (HY000/1045): Access denied for user 'timavnl_1'#'localhost' (using password: YES) in /home/timavnl/domains/tim-av.nl/public_html/6628/job/db_connect.php on line 2\nPHP message: PHP Warning: mysqli::prepare(): Couldn't fetch mysqli in /home/timavnl/domains/tim-av.nl/public_html/6628/job/index.php on line 5\nPHP message: PHP Warning: main(): Couldn't fetch mysqli in /home/timavnl/domains/tim-av.nl/public_html/6628/job/index.php on line 10\nPHP message: PHP Notice: Trying to get property of non-object in /home/timavnl/domains/tim-av.nl/public_html/6628/job/index.php on line 23\nPHP message: PHP Fatal error: Call to a member function fetch() on null in /home/timavnl/domains/tim-av.nl/public_html/6628/job/index.php on line 24\n'
My DB connect code:
<?php
$db = new mysqli("localhost","timavnl_1","password"."timavnl_1") or
die("ERROR! With connection");
?>
index.php code:
Picture of: index.php
You have a typo mistake. You have given . after password, change this with ,, use like this
"<"?php $db = new mysqli("localhost","timavnl_1","password","timavnl_1") or die("ERROR! With connection"); ?>
The right syntax for make a connection object is, parameters must be sephrated by , operator.
Syntax
$mysqli = new mysqli("localhost", "user", "password", "database");
Note: Depending on the connection function used, assorted parameters can be omitted. If a parameter is not provided, then the extension attempts to use the default values that are set in the PHP configuration file. Check the mannual here
The DB connect code appears to have a period . instead of a , between the password and database name.
ref: http://php.net/manual/en/mysqli.quickstart.connections.php
Try the following instead:
"<"?php $db = new mysqli("localhost","timavnl_1","password","timavnl_1") or die("ERROR! With connection"); ?>

Problems converting mySQL_pconnect to mySQLi_connect

I recently added an SSL certificate to my website and once it activated I got the following error when trying to view pages which are behind the login wall:
Warning: mysql_pconnect(): Access denied for user 'refini14_admin'#'70.39.144.73' (using password: YES) in /home/refini14/public_html/Connections/Database.php on line 9
Fatal error: Access denied for user 'refini14_admin'#'70.39.144.73' (using password: YES) in /home/refini14/public_html/Connections/Database.php on line 9
My hosting company's support has told me that this is because mysql_pconnect is not supported in current versions of php and that I should modify it to use a different sql connection method.
I have tried to modify my database connection file to connect using mysqli however am still getting errors. This is the code I am currently using to connect (I have replaced some details with *):
<?php
# FileName="Connection_php_mysql.htm"
# Type="MYSQL"
# HTTP="true"
$hostname_Database = "******";
$database_Database = "refini14_db";
$username_Database = "refini14_admin";
$password_Database = "*******";
$Database = mysqli_connect($hostname_Database, $username_Database, $password_Database) or trigger_error(mysqli_error(),E_USER_ERROR);
?>
I have only made modifications to line 9 as per the error message and have changed mysql_pconnect to mysql_connect. I am still getting the following error relating to mysqli_error():
Warning: mysqli_error() expects exactly 1 parameter, 0 given in /home/refini14/public_html/Connections/Database.php on line 9
Fatal error: in /home/refini14/public_html/Connections/Database.php on line 9
I am not experienced in mySQL and do not know how to resolve this error. Modifications I have made to mysqli_error() have not resolved the problem.
add your value and try:
<?php
$con = mysqli_connect("localhost","my_user","my_password","my_db");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
?>
mysqli_error() needs your connection variable i.e. $Database as a parameter so try it like this -
$Database = mysqli_connect($hostname_Database, $username_Database, $password_Database) or trigger_error(mysqli_error($Database),E_USER_ERROR);
instead of this -
$Database = mysqli_connect($hostname_Database, $username_Database, $password_Database) or trigger_error(mysqli_error(),E_USER_ERROR);

Warning: mysqli::mysqli(): in C:\xampp\htdocs\engine\classes\bd.Class.php on line 4 [duplicate]

I am writing some php script in the cpanel. When I access the website folder
(e.g. www.bbbbbb.com/folder/)
It give the warning like that.
Warning: mysqli::mysqli() [mysqli.mysqli]: (HY000/2005): Unknown MySQL server host 'host07.portalwebhosting' (1) in /home/restaur/public_html/restaurant/variables/variables.php on line 7
Warning: mysqli::set_charset() [mysqli.set-charset]: Couldn't fetch mysqli in /home/restaur/public_html/restaurant/includes/connect_database.php on line 3
Warning: mysqli::stmt_init() [mysqli.stmt-init]: Couldn't fetch mysqli in /home/restaur/public_html/restaurant/includes/login_form.php on line 45
Fatal error: Call to a member function prepare() on a non-object in /home/restaur/public_html/restaurant/includes/login_form.php on line 46
And I use the default account admin to access, it gives me the same result.
And here is my php coding
<?php
// database configuration
$host ="host07.portalwebhosting.com";
$user ="user";
$pass ="password";
$database = "monkey";
$connect = new mysqli($host, $user, $pass,$database) or die("Error : ".mysql_error());
// access key to access API
$access_key = "12345";?>
check your connection string or may be you need to try with port
$connection = new mysqli("host", "user", "pwd", "db", "3306");
no need to change port 3306 is default
why you use die("Error : ".mysql_error()); use mysqli

Read only mysql database

I'm trying to get work this small project. I have master-admin over classic admin.
my database connection is establish on cookie $key. If i have cookie google, it looks into my master-admin database and search there for DB_PASSWORD, DB_HOST etc. And then it build config.php.
This cookie is set to expire after few days.
This is my config.php :
<?php
$key = $_COOKIE["nazev_webu"];
$sql = mysql_query("SELECT * FROM weby WHERE nazev='$key'");
while($row = mysql_fetch_array( $sql )) {
// Print out the contents of each row into a table
$name = $row['DB_NAME'];
$pass = $row['DB_PASSWORD'];
$user = $row['DB_USER'];
$host = $row['DB_HOST'];
}
//připojení dataze
$connect = mysql_connect($host, $user, $pass)
or die("Nelze se připojit k databázi");
//výběr databáze
$select = mysql_select_db($name ,$connect)
or die("Nemohu vybrat databázi");
?>
it works perfectly but only in "read only mode". I can select from database but if I'm trying to insert or update something i get this error.
Warning: mysql_query() [function.mysql-query]: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) in /data20/website/html/config.php on line 7
Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /data20/website/html/config.php on line 7
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /data20/website/html/config.php on line 9
Warning: mysql_connect() [function.mysql-connect]: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) in /data20/website/html/config.php on line 20
I have to say that insert and update action are build on ajax call, so i post via ajax id of article f.e.. to the update script.
I think problem can be that mysql are on another server, not on the same server as is my website.
The solution is too easy. I forgot to include static database connection into this file. So it can't look into database and get from here connection details for new config.php.

remove mysqli_connect warning displaying in page

$mysqlServer = "***";
$mysqlDb = "***";
$mysqlUser = "***";
$mysqlPass = "***";
$conn = mysqli_connect($mysqlServer, $mysqlUser, $mysqlPass) or die("failed to connect to db");
mysqli_select_db($conn, $mysqlDb) or die("failed to connect select db");
i have this code, and its working without any problem. But if i try to input a wrong sql server or test it to perform an error. This will display:
Warning: mysqli_connect(): (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.
failed to connect select db
i don't want the warning to display if ever theres a problem in connecting the sql server. i just want my own error to display.
2 possible options:
set the error_reporing level to NOT to show warnings http://php.net/manual/en/function.error-reporting.php
put a # sign before mysqli_connect, this supresses the warning message
putting # sign before each function hide errors
$conn = #mysqli_connect($mysqlServer, $mysqlUser, $mysqlPass) or die("failed to connect to db");
Try this one:
$conn = mysqli_connect($mysqlServer, $mysqlUser, $mysqlPass, $mysqlDb);
Pass the DB name with the connect as fourth param.

Categories