Problems converting mySQL_pconnect to mySQLi_connect - php

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);

Related

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

Why do I get an internal server error from my SQL query?

I am attempting to retrieve some data from my database, I appear to be able to connect to the database as I do not get an error message after the connection is tested. But when I attempt to run a select query, it causes an internal error.
If I take the FROM part away from the query, the page loads with no data. If I add the FROM part back in, with the table to be selected from, the internal error occurs.
The code is below:
$con = mysqli_connect("50.62.209.87:3306","myusername","mypassword",
"FiveExtras");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$query = "SELECT `EventVenue`,`EventDate`,`EventTime`,
`EventPostCode` FROM `event`";
$result = mysqli_query($con, $query);
$row = $result;
echo $row;
Rewrite your connection:
$db_conn = mysqli_connect("$host", "$dbuser", "$dbpass") or die("Unable to connect to the database");
mysql_select_db("$dbase", $db_conn) or die("Unable to select the database");
$query = mysqli_query("SELECT `EventVenue`,`EventDate`,`EventTime`,
`EventPostCode` FROM `event`");
And why $result = $row ?
EDIT: For a better query , use "SELECT * ... "
did you change your htacess? Changes to .htacess often cause internal server error. or your host ip is bad(try no-ip.com, they give free subdomains for your ip's)
i checked it with removed port it worked(well...not connecting but no error about host), so maybe it's something to do with port
if error 500 remains try get support ticket or email webmaster or get another hosting provider
why would you say no error?
here we go:
Warning: mysqli_query() expects parameter 1 to be mysqli, boolean given
in /home/u451361813/public_html/test.php on line 13
and
Warning: mysqli_connect(): (28000/1045): Access denied for user
'myusername'#'185.28.20.221' (using password: YES) in /home/u451361813
/public_html/test.php on line 3
Failed to connect to MySQL: Access denied for user
'myusername'#'185.28.20.221' (using password: YES)
1st one is for no information returned second for no password

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.

php warning when logging in website folder by cpanel

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

Connect to 2 diffrent server at same time

I want to connect 2 diffrent DB, but I get that error:
Warning: mysqli::mysqli() [mysqli.mysqli]: (28000/1045): Access denied for user '*username*'#'localhost' (using password: YES) in......
my code:
$mysqli2 = new mysqli('localhost',$db_user,$db_pass, $db_name);
$mysqli2 = new mysqli('localhost',$db_user2,$db_pass2, $db_name2);
And I try to excute queries like this:
$result=$mysqli->query("select ......
$result=$mysqli2->query("select ......
How can I fix this?
Your username or password is wrong.
Your mysql user may not have the right privileges to connect over the network.
See here : How to grant remote access permissions to mysql server for user?
check password and adress and username
use next code to connect
$connect1 = new mysqli(...);
$connect2 = new mysqli()
if ($connect1->connect_error)
echo "error in 1 connection message: " . $connect1->connect_error;
if ($connect2->connect_error)
echo "error in 2 connection message: " . $connect2->connect_error;
where you see a problem ?

Categories