Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

$database->rand not working #991

Closed
syntax-error-1 opened this issue Jul 24, 2021 · 4 comments
Closed

$database->rand not working #991

syntax-error-1 opened this issue Jul 24, 2021 · 4 comments

Comments

@syntax-error-1
Copy link

syntax-error-1 commented Jul 24, 2021

Information

  • Version of Medoo: 2.1.1
  • Type of Database (MySQL, MSSQL, SQLite...): MySQL 8.0.8
  • System (Liunx\Windows\Mac): Windows

Describe the Problem

A clear and concise description of what the problem is.
$database->rand(); was working properly in the older version of mysql but after I updated my MySQL and php to version 8, the
rand function has stopped working.

Detail Code

$data = $database->rand("users", [
	"email"
], [
	"user_id[>]" => 1
]);

Expected output

Here is the error i am getting :
Fatal error: Uncaught PDOException: SQLSTATE[42000]: Syntax error or access violation: 1305 FUNCTION likesblast.NEWID does not exist in D:\Xampp\htdocs\likesblast\Medoo.php:563 Stack trace: #0 D:\Xampp\htdocs\likesblast\Medoo.php(563): PDOStatement->execute() #1 D:\Xampp\htdocs\likesblast\Medoo.php(1593): Medoo\Medoo->exec(Object(PDOStatement), Array) #2 D:\Xampp\htdocs\likesblast\Medoo.php(1988): Medoo\Medoo->select('users', Array, Array, NULL) #3 D:\Xampp\htdocs\likesblast\classes\test.php(9): Medoo\Medoo->rand('users', Array, Array) #4 {main} thrown in D:\Xampp\htdocs\likesblast\Medoo.php on line 563

@catfan
Copy link
Owner

catfan commented Jul 25, 2021

What's the code you actually called? What's the output of debug()?

NEWID() will be called if you set the database type as MSSQL. https://github.com/catfan/Medoo/blob/master/src/Medoo.php#L1974

Are you sure you set the database type to mysql correctly?

@syntax-error-1
Copy link
Author

Output of debug :

SELECT emailFROMusersWHEREuser_id > 1 ORDER BY NEWID()

And I have set the database to mysql, please check the code below :

`<?php

require '../Medoo.php';
// Using Medoo namespace
use Medoo\Medoo;

$database = new Medoo([
// required
'type' => 'mysql',
'database' => 'likesblast',
'host' => 'localhost',
'username' => 'root',
'password' => '',
]);

$data = $database->rand("users", [
"email"
], [
"user_id[>]" => 1
]);
var_dump($data);
?>
`

catfan pushed a commit that referenced this issue Jul 25, 2021
@catfan
Copy link
Owner

catfan commented Jul 25, 2021

Thanks for the feedback.

It fixed on 5f8f9f1.

@syntax-error-1
Copy link
Author

Thanks , it is working now .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants