Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mysql_error() is not working, when using mysqli_query() [closed]

Tags:

php

mysqli

No error showing using mysql_error() function. msqli_query() is working fine but when i add mysql_error beside it, i receive nothing in web page even thou the query is invalid and connection is wrong.

example. mysqli_query($link, $query) or die(mysql_error()); <--- Nothing comes up

link script:

<?php

#SET DATABASE CREDENTIALS
$mysql_host     = 'localhost';
$mysql_username = 'root';
$mysql_password = 'root';
$mysql_db   = 'attendance';
$mysql_error    = 'Error: connection';

//TEST CONNECTION
$link = mysqli_connect( $mysql_host, $mysql_username, $mysql_password, $mysql_db) or die($mysql_error);

if(mysqli_connect_errno())
{

printf("Connection Failed: %s\n", mysqli_connect_error());
exit();

}
?>

Query Script:

<?php

require('conn.php'); <--- **No Problem**

$query = "SELsECT * FROM `$TBL` WHERE `textFromDate` >= '".mysql_real_escape_string($date1)."' AND `textToDate` <= '".mysql_real_escape_string($date2)."' AND `Scheme`='Paid'";

$resultwholeday = mysqli_query($link, $wholeday) or die(mysql_error()); <--- **might have problem**


?>
like image 952
phphopzter Avatar asked Dec 20 '22 08:12

phphopzter


1 Answers

Use mysqli_error(): http://php.net/manual/en/mysqli.error.php

As far as I know (I may be wrong), every mysql_* function has a relative mysqli_* function. They do not work as substitutes.

EDIT (addressing comment):

According to PHP.net's mysqli_error() docs, it requires one argument to be passed:

string mysqli_error ( mysqli $link )

This mysqli $link that you are passing will be the variable that contains your database connection information. So you create a mysqli connection and save it to $link. Then run some queries. mysqli_error($link) will find the last error that has occurred on $link (or the mysqli connection).

like image 179
Sam Avatar answered Feb 01 '23 22:02

Sam