I have problem with php code connecting to MySQL [duplicate] - php

This question already has answers here:
Can I mix MySQL APIs in PHP?
(4 answers)
Closed 3 years ago.
I want to print all database name list that are in my wamp server mysql
and I'm getting some errors
$link_id=mysqli_connect('localhost','root',"");
$a=mysql_list_dbs($link_id);
while($row = mysqli_fetch_object($a))
{
echo $row->Database."<br>";
}
( ! ) Fatal error: Uncaught Error: Call to undefined function mysql_list_dbs() in C:\wamp64\www\connection.php on line 3
( ! ) Error: Call to undefined function mysql_list_dbs() in C:\wamp64\www\connection.php on line 3

You can not mix mysql_* and mysqli_* functions, they are two different APIs. The mysql_* functions have been deprecated and should no longer be used. mysqli_* doesn't have an equivalent function, but you can do mysqli_query($link_id, 'SHOW DATABASES') and then iterate over the results. See mysqli_query() for examples.

Related

PHP from 5.6 to 7.2 advice [duplicate]

This question already has answers here:
MySQLi equivalent of mysql_result()?
(12 answers)
How to change mysql to mysqli?
(12 answers)
Closed 11 months ago.
Fatal error: Call to undefined function mysqli_result()
I am having some issues migrating old code from Php 5.6 to 8 (I know, I'm late !).
The initial code was:
$datama=mysql_query("SELECT COUNT(*) as TOTALFOUNDA FROM errorlog WHERE IP ='$ff' and datenow>'$last' and counting='3'");
$anymatchesa=mysql_result($datama,0,"TOTALFOUNDA");
And I came up with this (the connexion to the DB with $conx is OK) :
$datama=mysqli_query($conx,"SELECT COUNT(*) as TOTALFOUNDA FROM errorlog WHERE IP ='$ff' and datenow>'$last' and counting='3'");
$anymatchesa=mysqli_result($datama,0,"TOTALFOUNDA");
But I get an error
Fatal error: Call to undefined function mysqli_result()...

How can i Solve this error : Uncaught Error: Call to undefined function mysql_real_escape_string() [duplicate]

This question already has answers here:
mysql_real_escape_string is undefined
(5 answers)
How can I prevent SQL injection in PHP?
(27 answers)
Why shouldn't I use mysql_* functions in PHP?
(14 answers)
Closed 1 year ago.
I am using PHP 8.0 Version but recently i get this error :
Uncaught Error: Call to undefined function mysql_real_escape_string()
is there any solution for this ?
mysql_real_escape_string was DEPRECATED in PHP 5.5.0 and REMOVED in PHP 7.0.0.¹
PHP recommends using MySQLi or PDO instead.
¹ https://www.php.net/manual/en/function.mysql-real-escape-string.php

Uncaught Error: Call to undefined function sql_regcase() [duplicate]

This question already has answers here:
Reference - What does this error mean in PHP?
(38 answers)
Fatal error: Uncaught Error: Call to undefined function sql_regcase
(2 answers)
Closed 3 years ago.
I know that using PHP functions to avoid anti-sql injections is a bad idea, but I'm trying solve this function issue for custom purposes
function anti_injection($sql){
$sql = preg_replace(sql_regcase("/(from|select|insert|delete|where|drop table|show tables|#|\*|--|\\\\)/"), "" ,$sql);
$sql = trim($sql);
$sql = strip_tags($sql);
$sql = (get_magic_quotes_gpc()) ? $sql : addslashes($sql);
return $sql;
}
I'm getting this error: Uncaught Error: Call to undefined function sql_regcase()
How can I solve this?
Thank you.
sql_regcase was deprecated in PHP 5.3.0, and removed in PHP 7.0.0.
https://www.php.net/manual/en/function.sql-regcase.php
This function was DEPRECATED in PHP 5.3.0, and REMOVED in PHP 7.0.0.
Alternatives to this function include:
preg_match()
preg_quote()
source https://www.php.net/manual/en/function.sql-regcase.php

Fatal error: Uncaught Error: Call to undefined function ereg_replace() PHP 7 [duplicate]

This question already has answers here:
How can I convert ereg expressions to preg in PHP?
(4 answers)
Closed 3 years ago.
below code is giving me the fatal error in php 7
$jquery_click_hook = ereg_replace("[^A-Za-z0-9]", "", strtolower($value['name']));
is there any way to make it compatible with php 7?
Switch to preg_replaceDocs and update the expression to use preg syntax (PCRE) instead of ereg syntax (POSIX) where there are differencesDocs (just as it says to do in the manual for ereg_replaceDocs).
Your above code should be this way:
$jquery_click_hook = preg_replace("[^A-Za-z0-9]", "", strtolower($value['name']));
ereg_replace function was DEPRECATED in PHP 5.3.0, and REMOVED in PHP 7.0.0. So you must have to use preg_replace() function instead of ereg_replace()

PHP Fatal error: Can't use method return value in write context [duplicate]

This question already has answers here:
Reference - What does this error mean in PHP?
(38 answers)
Closed 7 years ago.
if (isset( $xml->xpath('/lfm/artist/image[#size="extralarge"]')[0])) {
PHP Version 5.3 in use (was 5.7 until server dude switched it to 5.3).
On the line at the top we're getting this error:
PHP Fatal error: Can't use method return value in write context
I've read a few articles but nothing obvious springs to mind - might be a case of not seeing the wood through the trees.
Any advice on how to get rid of the error other than switching back to 5.7?
For compatibility with PHP < 5.4, update your code as follows:
$elements = $xml->xpath('/lfm/artist/image[#size="extralarge"]');
if (isset($elements[0])) {
Take a look at https://wiki.php.net/rfc/functionarraydereferencing if you're interested in learning more.

Categories