Search Posts

Author: Alex

PHP Dependency Injection when multiple types of databases are used in the same class

how to – PHP Dependency Injection when multiple types of databases are used in the same class I’m working on a very unorganized (no tests, logic mixed in everywhere) PHP application. I started reading the book Modernizing Legacy Applications In PHP and am now in the position where I need to replace global variables. In my case we have both MySQL and MongoDB mixed heavily throughout the application using global variables: $database for MySQL and […]

Is there a way to ‘interpoloate’ a column’s value as the comparison operator in the WHERE clause in MySQL?

how to – Is there a way to ‘interpoloate’ a column’s value as the comparison operator in the WHERE clause in MySQL? Let’s say I have a column named “comparison_operator” with values like ‘>’, ‘=’, ‘<‘. in the “products” table. Is there a way to use it in the WHERE clause like the following? SELECT products.name FROM products WHERE products.price #{comparison_operator} products.cost I believe the answer to this question is no but would like to […]

result of my js calculation is not stored in mysql

how to – result of my js calculation is not stored in mysql I have issues to store data from a simple js calculation. The calculation itself works as expected, but additionally I wanted to store the math calculation in a database where all values (the input fields and the result .textContent) should be stored. Afterwards the calculation should be named and populated by a dropdown menu, but that’s a different story. So, I added […]

SHOW COLUMNS returns error when used with prepared statement and LIKE

how to – SHOW COLUMNS returns error when used with prepared statement and LIKE I’m having troubles with the MySQL/MariaDB query below and I can’t figure out why. $field = ‘some_db_field’; $field = ‘%’ . $field . ‘%’; $query = $db->prepare( ” SHOW COLUMNS ” . ” FROM table” . ” LIKE :fieldName” ); $query->bindParam(‘:fieldName’, $field, PDO::PARAM_STR); $query->execute(); I get the following error: Fatal error: Uncaught exception ‘PDOException’ with message ‘SQLSTATE[42000]: Syntax error or access […]

load/safe html form with mysql stored data

how to – load/safe html form with mysql stored data I build a simple html/js math-form where some calculations are beeing made with. To simplify things I shortened the form to make it easier to understand: function output(){ var value1 = document.getElementById(‘value1’).value; var value2 = document.getElementById(‘value2’).value; var value3 = document.getElementById(‘value3’).value; document.getElementById(‘result1’).innerHTML = (parseInt(value1) + parseInt(value2)) * parseInt(value3); } <select> <option value=”volvo”>Simple Addition</option> </select><button type=”button”>Load</button> <button type=”button”>Save</button> <button type=”button”>Cancel</button> <br> <br> <br> Title: <input id=”Title” type=”text”/> […]

MySQL clause in where `case when`

how to – MySQL clause in where `case when` I am trying to figure it out but no solution at all. My query : SELECT * FROM table WHERE owner = ‘user’ AND ( CASE WHEN status = ‘NEW’ THEN status = ‘NEW’ ELSE status IN (‘CB’,’NA’,’NI’,’GC’,’FC’) END ) ORDER BY RAND() DESC LIMIT 1; What I want to achieve is to show all records where status is NEW in an Random order limited by […]

MySQL not showing my databse

how to – MySQL not showing my databse Trying to figure out how to view the tables/schema of a MySQL database, but after logging into the db with the root account I am not seeing any option to view the schema or tables of my DB. This is what I see: mysql I am still able to run queries against the db successfully but I need to be able to look at the table structure. […]

Creating database using mysql and querying information_schema leads to empty result

how to – Creating database using mysql and querying information_schema leads to empty result In a test case for a database utility I do the following Create and populate a test database using the mysql client tool Query information_schema.tables In the second step, I get an empty result. I already tried to use FLUSH TABLES during the import as well as ANALYSE tables before querying information_schema. I am running it with random database names. What […]

How to convert original MySQL Datatypes in R

I have a MySQL database with a lot of data in it. Now i want to manipulate it with R. After i run the MySQL Query, R imports the data but converts the datatypes of the tables. e.g. Datetime is converted to character and so on. And this is not the problem when just using the data in R. But after analysing it i want to write it back to the MySQL database with a […]

Table Lock & Performance Issue

All, We have Java-Spring-Hibernate-MySql based enterprise application. From the last few days we are facing table lock issues alot. Application is highly configurable and all rules are driven by values stored in database. When we upload data through excel there are lot of background consistency check happens before inserting data, or when user perform few action all of database tables are interacted (read and write) to execute the operation. We have MASTER-SLAVE configuration but application […]

Next Page »