Posts

Showing posts with the label mysql

Is better POW() or POWER()?

Image
Clash Royale CLAN TAG #URR8PPP Is better POW() or POWER()? I must make an exponentiation of a number and I don't know which function to use between POW() and POWER() . Which of the two functions is better? POW() POWER() Looking at the MySQL documentation I saw that they are synonymous, but I wanted to understand if there was a reason for two functions that do the same thing. By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Sql Table data formation

Image
Clash Royale CLAN TAG #URR8PPP Sql Table data formation I have a below table ID Level StoreId 2604553 3 A 2604553 7 C 2604553 7 D 2604553 7 E 2678540 3 A 2678540 7 A 2678540 3 B 2678540 7 B 2678540 3 C I need out put like Below ID A B C D E 2604553 3 0 7 7 7 2678540 3 3 3 0 0 2678540 3 7 3 0 0 2678540 7 3 3 0 0 2678540 7 7 3 0 0 Please help me how to achieve this. By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Reformat first row column based on other rows

Image
Clash Royale CLAN TAG #URR8PPP Reformat first row column based on other rows I have a table which contains US cities, some cities have multiple zip codes and they are one row with one zip code as shown below in the screen shot, I want this to be store as one row per city with their multiple zip codes in comma split format in the zip column, Is there any way to do this? Expected result would be like below image By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

How to iterate through cursor after mysql select * query in python?

Image
Clash Royale CLAN TAG #URR8PPP How to iterate through cursor after mysql select * query in python? I am querying all the fields of a mysql table like this - query = """select * from %s where %s=%s;""" % (tableName,key,value) cursor.execute(query) Now, I would like to iterate over the results. I do not want to specify the column names which I would like to fetch as I would like to fetch all. This is part of a generic migration verification script which is supposed to do the verification for all the mysql tables. Since there will be different number of columns in different tables, I would like a general solution. I checked https://stackoverflow.com/a/25347195/351903 but it involves specific fields. By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject t...

how to print 1st reminder, 2nd reminder in gridview yii2 from model?

Image
Clash Royale CLAN TAG #URR8PPP how to print 1st reminder, 2nd reminder in gridview yii2 from model? Here is my view page view.php view.php <div class="dataTables_wrapper form-inline dt-bootstrap"> <?= GridView::widget([ 'dataProvider' => $dataProvider1, 'columns' => [ ['class' => 'yiigridSerialColumn'], [ 'label' =>'Date', 'value' => 'date', ], [ 'label' =>'Reminder', 'value' => function($model){ return Yii::$app->session->get('').' '.$model['type'].' '.'reminder'; } ], [ 'label' =>'To', 'value' => 'recipients', ...

Mysql Query to count common number in a column

Image
Clash Royale CLAN TAG #URR8PPP Mysql Query to count common number in a column I have a main table as first image and I need to produce output as second table. Can any one please help me to do mysql query. Main Table Output 1 Answer 1 You can do : select anumber, sum(tsp = 'aplace') as aplace, sum(tsp = 'bplace') as bplace, sum(tsp = 'cplace') as cplace from table t group by anumber; By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

upload file (pdf,JPEG/FIF) to mysql using java

Image
Clash Royale CLAN TAG #URR8PPP upload file (pdf,JPEG/FIF) to mysql using java Is there any way to attach file to mysql in java , I need the file to be inside the database not the path . Possible duplicate of Storing Image in Data Base Using Java in Binary Format – dieend 10 hours ago Can you provide some more context? What have you tried so far, and what are you struggling with? – Nico Haase 1 hour ago 2 Answers 2 Use base64 enconding and save it as BLOB data This is an example of encoding: /** * Method used for encode the file to base64 binary format * @param file * @return encoded file format */ private...

How to make URL display as link with https along with current code for http in php?

Image
Clash Royale CLAN TAG #URR8PPP How to make URL display as link with https along with current code for http in php? Thank you for your help. I currently am using the following code to return URLs as live links on My site: //$bodymessage=preg_replace('`((?!##RAQ.*?##)(?<!@)s[A-Z0-9._-]*.[A-Z]{2,3}[^ ]*?(?!<[^ .]))([ rn.])`sim', '##RAQ_URL1##1..2##RAQ_URL1##', $bodymessage); $a_search = array ( '`((?!##RAQ.*?##)[A-Z0-9._%-]+@[A-Z0-9._%-]+.[A-Z0-9._%-]{2,4})b`sim', '`((?!##RAQ.*?##)(?<!@)http://[A-Z0-9._-]*.[A-Z]{2,3}[^ ]*?(?!<[^ ]))([ rn])`sim', '`##RAQ_URL1##(.*?)..(.*?)##RAQ_URL1##`sim', '`##RAQ_EMAIL##(.*?)##RAQ_EMAIL##`sim', ); $a_replace = array ( '##RAQ_EMAIL##1##RAQ_EMAIL##', '##RAQ_URL1##1..2##RAQ_URL1##', '<a href="1">1</a>2', '<a href="mailto:1">1</a>', ); $message = nl2br(preg_replace($a_search, $a_replace, $bodymessage)); The scrip...

Python PayPal IPN import MYSQL Euro Characters Fail

Image
Clash Royale CLAN TAG #URR8PPP Python PayPal IPN import MYSQL Euro Characters Fail I have a python3 to work as a PayPal IPN Receiver. So far it's okay, but when there are some European Characters are not success to insert into MYSQL Table. For Example: Skořepová insert into MYSQL table will become Sko?epová The IPN Message is something like this: address_name=Cool+Sko%C5%99epov%C3%A1&address_state=Jind%C5%99ich%C5%AFv+Hradec Below is my code: def index(self, **data): db = mysql.connector.connect(host="xxxxxxxx",user="xxxxxx",passwd="xxxxxx",db="xxxx",charset="utf8") cursor = db.cursor(buffered=True) for k,v in data.items(): print(k,v) cursor.execute(u"INSERT INTO tablename VALUES(NULL,%s,%s)",(k,v)) The print result is "Cool Skořepová" But MYSQL is "Cool Sko?epová" Yes, the á is no problem to insert, but some characters such as this ř is not. And I have tried to insert di...

Converting MYSQL to WordPress $WPDB

Image
Clash Royale CLAN TAG #URR8PPP Converting MYSQL to WordPress $WPDB I’m upgrading an archaic Wordpress site from 3.7. It has some SQL query requests that don’t function after 3.9+ where you now have to connect to the DB via $WPDB. I've taken an initial stab at it but am hung up on the mysql_fetch_array part and also unclear if what I've already done is even correct. Seems like the mysql_fetch_array needs to use get_results. I'm fully aware that this is a less than ideal way to approach this and fully intend to modernize everything but in keeping a long story short it would be very helpful to be able to sort this out within this old jumbled paradigm if at all possible. Attached is the original code and then my attempt (also added a v2 attempt) . Thanks for taking a look. SQL: $sql = "SELECT wp_acf_values.value FROM wp_acf_values, wp_acf_fields WHERE wp_acf_fields.post_id = '620' AND wp_acf_fields.id = wp_acf_values.field_id ORDER BY wp_acf_fields.order_no"; ...

mysql version 8.0.11 and Symfony 4 error “MySQL server has gone away”

Image
Clash Royale CLAN TAG #URR8PPP mysql version 8.0.11 and Symfony 4 error “MySQL server has gone away” I' m using Symfony 4 and Mysql version is 8.0.11 and using a user instead of a root login and when i try to use the command php bin/console make:migration i get this error: php bin/console make:migration In AbstractMySQLDriver.php line 126: An exception occurred in driver: SQLSTATE[HY000] [2006] MySQL server has gone away In PDOConnection.php line 50: SQLSTATE[HY000] [2006] MySQL server has gone away In PDOConnection.php line 46: SQLSTATE[HY000] [2006] MySQL server has gone away In PDOConnection.php line 46: PDO::__construct(): Unexpected server respose while doing caching_sha2 auth: 109 Then i tried to search online and i found out th...

Login form in mysql

Image
Clash Royale CLAN TAG #URR8PPP Login form in mysql I am using Mysql netbeans . I have created a db table "userdetails_summertrainingproject" . In the login form I have two fileds to fill one is "UUId_JTextField" and other is "Password1_JPasswordField". I want to compare that the password value entered by the user is same as that in db for the particular UUId entered by the user. UUid is unique. try{ Class.forName("com.mysql.jdbc.Driver"); Connection conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/mysql","root",""); String query = "SELECT password FROM userdetails_summertrainingproject WHERE UUId=?;"; PreparedStatement preparedStatement = conn.prepareStatement(query); preparedStatement.setString(1,UUId_JTextField.getText()); ResultSet rs = preparedStatement.executeQuery(); ...

Access denied for user with GRANT priviliege

Image
Clash Royale CLAN TAG #URR8PPP Access denied for user with GRANT priviliege I have a DB named abc_products , with various tables. One of them is named table1 . abc_products table1 I created a new DB user named abc_user , and want to restrict its DB access only to that table. abc_user I logged to SSH Terminal as root user, and typed: root root@host [~]# mysql Welcome to the MySQL monitor. Commands end with ; or g. Your MySQL connection id is 5721225 Server version: 5.6.39 MySQL Community Server (GPL) mysql> use abc_products Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed mysql> GRANT SELECT ON `table1` TO 'abc_user'@'localhost'; Query OK, 0 rows affected (0.00 sec) But when I try to connect to MySQL with this user, I get an access denied error in my Chrome Console XHR response: Connect failed: Access denied for user 'abc_user'@'localhost' (using pa...

How can write this query in sql?

Image
Clash Royale CLAN TAG #URR8PPP How can write this query in sql? Tables: TEAMS( tid , tname, tcolor, budget) PLAYERS( pid , pname, age, country) PLAYS( pid , tid , season, value) -(pid references to pid in PLAYERS table) -(tid references to tid in TEAMS table) WINS( wtid , ltid , season, wscore, lscore) -(wtid (winner) and ltid (loser) references to tid in TEAMS table) I have to write query for this:(I tried with "not exist" and "not in" but could not do it.) Find tid of teams that played with all teams. 1) please show what you tried, even if it didn't work. Then we know you did try. 2) Please explain the structure of your database. 3) You've shown us some fields but not explained what the output of the query should be (i.e what the rules are, what should / should not be included, and what the criteria for that are). Ideally show us some example source data and example of what they query output would be based on that source data....

mysql Update subquery Table is Specified twice

Image
Clash Royale CLAN TAG #URR8PPP mysql Update subquery Table is Specified twice i try this subquery to decerese 1 i my quantity every time i execute this query , i think it will work on sqlServer but why its not working on mysql. im getting this error Table 't1' is specified twice, both as a target for 'UPDATE' and as a separate source for data heres my code Update tblbooks AS t1 set t1.Quantity = (Select t2.Quantity-1 from tblbooks AS t2 where t2.BookId = 123) where t1.BookId = 123 1 Answer 1 You don't need the subquery there - you can reassign a calculation on a column back to the same column: UPDATE tblbooks SET Quantity = Quantity - 1 WHERE BookId = 123 hahaha,i feel bad for me ,thank you – Ivan 2 mins ago ...

Location of my.cnf file on macOS

Image
Clash Royale CLAN TAG #URR8PPP Location of my.cnf file on macOS I'm trying to follow along this tutorial to enable remote access to MySQL. The problem is, where should my.cnf file be located? I'm using Mac OS X Lion. my.cnf I think this belongs to serverfault.com. But still, welcome to SO! – Artefact2 May 25 '12 at 15:28 21 Answers 21 This thread on the MySQL forum says: By default, the OS X installation does not use a my.cnf, and MySQL just uses the default values. To set up your own my.cnf, you could just create a file straight in /etc. OS X provides example configuration files at /usr/local/mysql/support-files/ . /usr/local/mysql/support-files/ And if you can't find them there, MySQ...