Medoo
The lightest PHP database framework to accelerate development
Medoo - The lightest PHP database framework to accelerate development the lightest php database framework to accelerate development.
Hey guys (this is my first question here). i've got some problems today So,i need some helps.
My code look like this:
$database->update($campaign_table, $data_nga_posti , array("AND" => ["codice_pod" => $data_nga_posti['codice_pod'],("codice_pdr" =>NULL) ]));
So this is when my query execute:
UPDATE `field` SET `columnname` = 'data',`anothercm` = 'data',WHERE `codice_pod` = 'IT001E35563561' AND `codice_pdr` IS NULL
I want to my query look like this.
UPDATE `field` SET `columnname` = 'data',`anothercm` = 'data',WHERE `codice_pod` = 'IT001E35563561' AND (`codice_pdr` IS NULL OR `codice_pdr` ="")
but i dont know how to put OR(operator ) inside this code.
Thank you very much!
Source: (StackOverflow)
I have problem with Medoo framework, all work fine on localhost (php > 5.4+) but on my server I have instaled PHP 5.3+, can you help me how I can convert this code to old array version and execute code on PHP 5.3. platform.
$database = new medoo array(
// required
'database_type' => 'mysql',
'database_name' => 'mytable',
'server' => 'localhost',
'username' => 'root',
'password' => '',
// optional
'port' => 3306,
'charset' => 'utf8',
'option' => [
PDO::ATTR_CASE => PDO::CASE_NATURAL
]
);
$database->insert("table", [
"project_name" => "Some text",
"project_owner" => "Some Text",
"project_time" => "10/10/2014",
"project_target" => "- Target one, - Target two, - Target three",
"project_details" => "This is my project."
]);
Source: (StackOverflow)
My script allows you to upload a zip file and then inserts the individual file information into a database using Medoo, after extracting them. My script takes way too long to finish, even after I've set the max execution time to 5 minutes I get the notice saying the max execution time has been exceeded.
There are only about 650 files in the zips that will be upload-able and the script only manages to extract and insert about half in to the DB before it times out. Is this query more memory intensive than I realize?
EDIT: I should mention that it only hangs with zip files with a larger amount of files, like the 650 figure I mentioned above, the program seems to execute fine with a small number of files.
Code (Offending query near bottom of script):
<?php
ini_set('max_execution_time', 300);
require_once 'vendor/medoo.min.php';
require_once 'scripts/class.file.php';
$database = new medoo([
'database_type' => 'mysql',
'database_name' => 'invoice_files',
'server' => 'localhost',
'username' => 'root',
'password' => 'pass',
'charset' => 'utf8'
]);
$file = new File();
$file->set("filename", $_FILES['uploaded-file']['name']);
$file->set("category", "Invoice Statement");
$file->set("file_temp_path", $_FILES["uploaded-file"]["tmp_name"]);
$file->set("uploadedFilePath", $file->path("uploads/") . basename($file->get("filename")));
$counter = 0;
if($file->getPathInfo()["extension"] == "zip")
{
$zip = new ZipArchive;
$zipFile = $file;
echo "Source: " . $zipFile->get("file_temp_path") . "<br>";
if($zip->open($zipFile->get("file_temp_path")))
{
for($i = 0; $i < $zip->numFiles; $i++)
{
$zipName = $zip->getNameIndex($i);
$zipFile->set("uploadedFilePath", $file->path("uploads/"));
$zipFile->set("filename", $zipName);
for($x = 0; $x < $zip->numFiles; $x++)
{
$extension = $zip->getNameIndex($x);
$pathInfo = pathinfo($extension);
if($pathInfo["extension"] != "pdf" && $pathInfo["extension"] != "xls")
{
echo "Non PDF or excel sheet detected<br>";
return false;
}
if($pathInfo["extension"] == "xls")
{
$excelFile = $extension;
$excelFlag = true;
}
else
{
$excelFlag = false;
}
}
if($zip->extractTo($zipFile->get("uploadedFilePath")))
{
$pathInfo = pathinfo($zipName);
$database->insert('files',[
'name' => $zipFile->get("filename"),
'category' => $zipFile->get("category"),
'date' => $zipFile->setDate(),
'extension' => $pathInfo["extension"],
'size' => filesize($zipFile->get("uploadedFilePath") . $zipFile->get("filename")) / 1000 . 'KB',
'path' => $zipFile->get("uploadedFilePath") . $zipFile->get("filename")
]);
}
else
{
echo "Failure to extract<br>";
}
}
}
if($excelFlag)
{
$url = "insert-new-clients.php?excelfile=" . urlencode($excelFile);
//header("location:$url");
}
}
else
{
echo "File not in zip format";
return false;
}
?>
Source: (StackOverflow)
Is it possible to get number of selected rows using Medoo? I havent found anything about it in the documentation.
Like num_rows() in mysqli or rowCount in pdo.
Source: (StackOverflow)
I'm using Medoo Framework to handle my database queries. It is basically a PDO wrapper, I didn't find in their documentation how to handle errors or check the result, sometimes it return empty array, sometimes FALSE sometimes 0 etc.
As I couldn't understand how to handle errors this is what I'm doing currently using empty() because it can handle FALSE , 0 and empty Array I think it's okay here):
On SELECT (Medoo returns array)
// Same as:
// SELECT username FROM accounts WHERE id=$id AND suspended=0
$select = $database->select("accounts",["username"], [
"AND" => [
"id" => $id,
"suspended" => 0
]
]);
// I have to check if Query failed also if row was not found
if (empty($select) === FALSE && count($select) > 0)
{
// It didn't FAIL
// So i get username like this:
$key = array_keys($select)[0];
$username = $select[$key]['username'];
}
else
{
// It FAILED
}
On INSERT (Medoo says it returns INSERT ID here)
$insert = $database->insert("accounts", [
"username" => "$username"
]);
// Check if query didn't fail and actually inserted (affected rows i think?)
if (empty($insert) === TRUE OR $insert < 1)
{
// It Failed
}
On UPDATE (This is actually the only clear query, it returns affected rows)
$update = $database->update("accounts", ["brute_force[+]" => 1], ["id" => $user_id]);
if (empty($update) === TRUE OR $update < 1)
{
// It FAILED
}
// Check if query didn't fail and also affected row
I am so confused and unsure about these that I'm paranoid maybe I should just completely rewrite and use CodeIgniter like I always do.
Source: (StackOverflow)
I'm trying to make a left join select and use AND to compare a column against a specific value, i.e. a condition.
The problem is I don't know where to add the condition. The below medoo query returns the first shirt id of the same user id even if all 'is_wearing_shirt' set to 0. A regular mysql query however returns the expected data.
Here's the medoo query:
$db->select('users', array(
'[>]shirts' => array(
'user_id' => 'shirt_owner_id',
'is_wearing_shirt' => 1 // equivalent to AND is_wearing_shirt = 1
)
), array(
'user_id',
'shirt_id(shirt_id_being_worn)'
) , array(
'user_id' => 1,
'LIMIT' => 1
));
// always returns a shirt_id (even if all rows have is_wearing_shirt set to 0, in which case, shirt_id should be null)
Here's the regular MySQL query that works:
SELECT u.user_id, s.shirt_id
FROM `cvs_users` u
LEFT JOIN `shirts` s
ON user_id = shirt_owner_id
AND shirt_being_worn = 1
WHERE user_id = 1
//returns the correct shirt_id
Source: (StackOverflow)
I am using Medoo. the update below works fine with single field match. I want to update data if match with clientId and businessCity.
$database->update("clientInfo", array(
"businessName" => $_POST['businessName'],
"contactName" => $_POST['contactName'],
"businessEmail" => $_POST['businessEmail'],
"businessPhone" => $_POST['businessPhone'],
"businessWebsite" => $_POST['businessWebsite'],
"businessAddress" => $_POST['businessAddress'],
"businessAddress2" => $_POST['businessAddress2'],
"businessCity" => $_POST['businessCity'],
"businessState" => $_POST['businessState'],
"businessZip" => $_POST['businessZip']
), array(
"clientId" => $_POST['clientId'],
"businessCity" => $_POST['businessCity'],
));
I tried like this. but not working for me.
Source: (StackOverflow)
Im just starting out building an app with Medoo,
Im trying to run a select query looking like this
$datas = $database->debug()->select(
"table",
["id","password"],
["email" => "johndoe@emailaddress.com"]
);
When i run this it uses the query
SELECT "id","password" FROM "table" WHERE "email" = 'johndoe@emailaddress.com'
However this always returns NULL
Inserting to the DB runs correctly, and when I try to run the query generated by medoo directly in mysql CLI it returns a syntax error.
Im struggling to find an issue with the syntax, perhaps maybe the "' quotes?
PHP Version: PHP 5.4.41
MySQL: mysql Ver 14.14
Medoo: 0.9.8.3
Thanks for any help
Source: (StackOverflow)
I have the debug modus on and get this
mySQL string:
SELECT "dmd_key","id"
FROM "keys"
WHERE "dmd_key" = '140ec37b981042c8549b07d6d4589295'
AND "website" = 'test.de'
But that string doesn't work for me. I get a database error message. (the standard message..)
If I change my string into this:
SELECT `id`,`dmd_key`
FROM `keys`
WHERE `dmd_key` = '140ec37b981042c8549b07d6d4589295'
AND `website` = 'test.de'
I get results.
I think I have to change something in my settings but I don't know what.
It is my first time with medoo and I think medoo doesn't love me...
Thanks for your help.
Source: (StackOverflow)
English is not first my language so please bear with me.
Table Structre:
Product Table
productid | name | slug | cover
1 EX1 ex1 ex1.png
2 EX2 ex2 ex2.png
Tag Table
tagid | name | slug | typeid
1 t1 ex1 1
2 t2 ex5 2
3 t3 ex2 3
4 t4 ex3 2
5 t5 ex4 4
Tagging Table
id | productid | tagid
1 ex1 t1
1 ex1 t2
I'm trying to get related product based on the tags that was tagged to that product.
For example: I have product EX1 tagged with t1, t2, t3 and I want to search for other products that were tagged with these 3 tags (all 3 tags not one out of ).
What I have in mind is creating another table like this
productid | tagged_list
1 t1,t2,t3,t4
2 t1,t3,t4
3 t1,t3,t4
Then this would give me the related products:
SELECT tagged_list FROM tagged_list WHERE productid = 2;
$result = t1,t3,t4 then use PHP to make it look like '%t1,%t3,%t4,%'
SELECT *
FROM products p
JOIN tagged_list tl USING (productid)
WHERE tl.tagged_list LIKE '.$result
I don't think this is the most efficient way to do this as the product table has more than 10,000 records and the tagging table is about x4 more than that. If you know a better way to do this, please help this newbie.
Thanks!!!
Source: (StackOverflow)
i am using the "medoo"-php/mysql-class (http://www.medoo.in) for my latest project. I like the quiet easy way to work with my SQL-stuff.
But i wondered if it is possible to change the search term according to an option from an input-select-form. Lets say we got search-option "user by name", we would go with:
$data = $database->select("account", [
"user_name",
"user_id",
"phone",
"email",
"age"], [
"user_name" => $_POST['user_name']]);
Fine so far. Now we get the search option "user by ID". Every thing else stays just the same. So i need only the
["user_name" => $_POST['user_name']]);
to be like
["user_id" => $_POST['user_id']]);
Is there a way to change that without writing the whole statement again?
It is just a example. Moreover for my project i will need to change other options of the query like update to insert oder different join-options. But for the moment i am fine with an answer to that.
Anyway, what do you think about the Medoo-Class. Got any cool alternative Class-solutions for me? Basically i know how to work with SQL querys but getting stuff to the array at the end is always driving me crazy. So i would love to get stuff faster and easier with a class.
Thx a lot for your help!
Best, Lox
Source: (StackOverflow)
I am learning PHP by myself. I am using Slim framework with Medoo and creating a login page and when executing login page there is no error. but when calling "call_query
" function error occur saying :
Undefined variable: database in
C:\xampp\htdocs\class\blog\pages\login.php on line 8
and
Fatal error: Call to a member function select() on a non-object in
C:\xampp\htdocs\class\blog\pages\login.php on line 8
In code i have created an object $database
then using select
method on it.
<?php
require_once 'medoo.php';
$database = new medoo();
session_start();
$login_error = $br = null;
function call_query(){
$data = $database->select('user', 'user_name', [
'user_name'=>$_POST['u_name'],
'password'=>$_POST['pass']
]);
if (count($data) == 1) {
header("location : localhost/class/blog");
}else{
$login_error = "Wrong Username or Password";
$br = "<br><br>";
}
}
if ($_SERVER['REQUEST_METHOD'] == 'POST' && $_POST['submit'] == 'submit'){
if (isset($_POST['u_name']) && isset($_POST['pass']) && !empty($_POST['u_name']) && !empty($_POST['pass'])) {
if (isset($_SESSION['username']) && isset($_SESSION['password'])) {
if ($_SESSION['username'] == $_POST['u_name'] && $_SESSION['password'] == $_POST['pass']) {
header("location : localhost/class/blog");
}else{
call_query();
}
}else{
call_query();
}
}else{
$login_error = "Enter both Username and Password to login.";
$br = "<br><br>";
}
}
echo '<form action = "pages/login.php" method = "post">
<label>Username : </label><input type ="text" name ="u_name"><br><br>
<label>Password : </label><input type = "password" name = "pass"><br><br>
'.$login_error.$br.'
<input type ="submit" name = "submit" value = "submit">
</form>';
?>
Source: (StackOverflow)
Is it possible to include strtotime date comparison parameters when using medoo to SELECT rows from a database?
I'm using medoo to make database work nice & simple - it's great. However, I'm not sure if I can (but suspect I can) include a date range like parameter when getting rows from my database.
Instead of going through all rows in a foreach routine of what is a large database, I was hoping I could optimise my SELECT/WHERE calls. My loose example/idea is here, but I'm not sure what will work.
$thelogs = $database->select("system_logs", array(
"date",
"category",
"description",
"class"), array(
"date" => .........strtotime('-7 day')
));
...More information pertaining the way dates are being saved.
Date column is set to datetime in MySQL
Example entry would be: 2014-12-21 05:31:22
In php i'm just using date('Y-m-d H:i:s')
Source: (StackOverflow)
I do not understand why there is replace
method in the Medoo class.
What is difference between this and a update
call?
Source: (StackOverflow)
I have a control panel using jtables and medoo.
Everything works great - rows are added/deleted and displayed correctly
The issue is when I try to Add or update a record using jtables.
The record is updated in the DB just fine, but the popup dialog does not dissapear...
there are no JS errors and the returned date looks fine.
For example:
For the following table:
$('#usersContainer').jtable({
title: 'Users',
paging: true,
pageSize:7,
sorting:true,
actions: {
listAction: './ajax/user/get_user.php',
createAction: './ajax/user/create_user.php',
updateAction: './ajax/user/update_user.php',
deleteAction: './ajax/user/delete_user.php'
},
fields: {
id: {
key: true,
list: false
},
username: {
title: 'Username',
},
hashed_password: {
title: 'Password',
type: 'password',
},
last_login_time: {
title: 'Last Login',
edit: false,
create:false,
},
}
});
the create_user.php returns the following:
{"Result":"OK","Records":{"id":"9","username":"aaa","hashed_password":"$2y$10$KSFPhT9gEqI49P.3b1mRler40gk1RMHl4itXyscQCf6xhtQmlTkdm","last_login_time":null}}
but the popup does not disappear
any lead will help
Source: (StackOverflow)